<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FFile_Input_Output%2FWriter</id>
		<title>Java/File Input Output/Writer - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FFile_Input_Output%2FWriter"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/File_Input_Output/Writer&amp;action=history"/>
		<updated>2026-04-21T18:46:22Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/File_Input_Output/Writer&amp;diff=6225&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/File_Input_Output/Writer&amp;diff=6225&amp;oldid=prev"/>
				<updated>2010-06-01T06:04:34Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:04, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/File_Input_Output/Writer&amp;diff=6224&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/File_Input_Output/Writer&amp;diff=6224&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:43Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== A writer for char strings ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
/* Copyright (c) 2001-2009, The HSQL Development Group&lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions are met:&lt;br /&gt;
 *&lt;br /&gt;
 * Redistributions of source code must retain the above copyright notice, this&lt;br /&gt;
 * list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistributions in binary form must reproduce the above copyright notice,&lt;br /&gt;
 * this list of conditions and the following disclaimer in the documentation&lt;br /&gt;
 * and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 * Neither the name of the HSQL Development Group nor the names of its&lt;br /&gt;
 * contributors may be used to endorse or promote products derived from this&lt;br /&gt;
 * software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &amp;quot;AS IS&amp;quot;&lt;br /&gt;
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE&lt;br /&gt;
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE&lt;br /&gt;
 * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,&lt;br /&gt;
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;&lt;br /&gt;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND&lt;br /&gt;
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT&lt;br /&gt;
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
/**&lt;br /&gt;
 * A writer for char strings.&lt;br /&gt;
 * &lt;br /&gt;
 * @author Fred Toussi (fredt@users dot sourceforge.net)&lt;br /&gt;
 * @version 1.9.0&lt;br /&gt;
 * @since 1.9.0&lt;br /&gt;
 */&lt;br /&gt;
public class CharArrayWriter {&lt;br /&gt;
  protected char[] buffer;&lt;br /&gt;
  protected int count;&lt;br /&gt;
  public CharArrayWriter(char[] buffer) {&lt;br /&gt;
    this.buffer = buffer;&lt;br /&gt;
  }&lt;br /&gt;
  public void write(int c) {&lt;br /&gt;
    if (count == buffer.length) {&lt;br /&gt;
      ensureSize(count + 1);&lt;br /&gt;
    }&lt;br /&gt;
    buffer[count++] = (char) c;&lt;br /&gt;
  }&lt;br /&gt;
  void ensureSize(int size) {&lt;br /&gt;
    if (size &amp;lt;= buffer.length) {&lt;br /&gt;
      return;&lt;br /&gt;
    }&lt;br /&gt;
    int newSize = buffer.length;&lt;br /&gt;
    while (newSize &amp;lt; size) {&lt;br /&gt;
      newSize *= 2;&lt;br /&gt;
    }&lt;br /&gt;
    char[] newBuffer = new char[newSize];&lt;br /&gt;
    System.arraycopy(buffer, 0, newBuffer, 0, count);&lt;br /&gt;
    buffer = newBuffer;&lt;br /&gt;
  }&lt;br /&gt;
  public void write(String str, int off, int len) {&lt;br /&gt;
    ensureSize(count + len);&lt;br /&gt;
    str.getChars(off, off + len, buffer, count);&lt;br /&gt;
    count += len;&lt;br /&gt;
  }&lt;br /&gt;
  public void reset() {&lt;br /&gt;
    count = 0;&lt;br /&gt;
  }&lt;br /&gt;
  public void reset(char[] buffer) {&lt;br /&gt;
    count = 0;&lt;br /&gt;
    this.buffer = buffer;&lt;br /&gt;
  }&lt;br /&gt;
  public char[] toCharArray() {&lt;br /&gt;
    char[] newBuffer = new char[count];&lt;br /&gt;
    System.arraycopy(buffer, 0, newBuffer, 0, count);&lt;br /&gt;
    return (char[]) newBuffer;&lt;br /&gt;
  }&lt;br /&gt;
  public int size() {&lt;br /&gt;
    return count;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Converts input data to a string.&lt;br /&gt;
   * &lt;br /&gt;
   * @return the string.&lt;br /&gt;
   */&lt;br /&gt;
  public String toString() {&lt;br /&gt;
    return new String(buffer, 0, count);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Null Writer ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
     &lt;br /&gt;
/*&lt;br /&gt;
  Milyn - Copyright (C) 2006&lt;br /&gt;
  This library is free software; you can redistribute it and/or&lt;br /&gt;
  modify it under the terms of the GNU Lesser General Public&lt;br /&gt;
  License (version 2.1) as published by the Free Software&lt;br /&gt;
  Foundation.&lt;br /&gt;
  This library is distributed in the hope that it will be useful,&lt;br /&gt;
  but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&lt;br /&gt;
  See the GNU Lesser General Public License for more details:&lt;br /&gt;
  http://www.gnu.org/licenses/lgpl.txt&lt;br /&gt;
*/&lt;br /&gt;
import java.io.Writer;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
/**&lt;br /&gt;
 * Null writer implementation.&lt;br /&gt;
 * &amp;lt;p/&amp;gt;&lt;br /&gt;
 * Data writen to this writer is swallowed (ala piping output to &amp;lt;i&amp;gt;/dev/null&amp;lt;/i&amp;gt;).&lt;br /&gt;
 *&lt;br /&gt;
 * @author &lt;br /&gt;
 */&lt;br /&gt;
public class NullWriter extends Writer {&lt;br /&gt;
    private Writer parentWriter;&lt;br /&gt;
    public NullWriter() {&lt;br /&gt;
        super();&lt;br /&gt;
    }&lt;br /&gt;
    public NullWriter(Object lock) {&lt;br /&gt;
        super(lock);&lt;br /&gt;
    }&lt;br /&gt;
    public NullWriter(Writer parentWriter) {&lt;br /&gt;
        super();&lt;br /&gt;
        this.parentWriter = parentWriter;&lt;br /&gt;
    }&lt;br /&gt;
    public Writer getParentWriter() {&lt;br /&gt;
        return parentWriter;&lt;br /&gt;
    }&lt;br /&gt;
    public void write(int c) throws IOException {&lt;br /&gt;
    }&lt;br /&gt;
    public void write(char cbuf[]) throws IOException {&lt;br /&gt;
    }&lt;br /&gt;
    public void write(String str) throws IOException {&lt;br /&gt;
    }&lt;br /&gt;
    public void write(String str, int off, int len) throws IOException {&lt;br /&gt;
    }&lt;br /&gt;
    public Writer append(CharSequence csq) throws IOException {&lt;br /&gt;
        return this;&lt;br /&gt;
    }&lt;br /&gt;
    public Writer append(CharSequence csq, int start, int end) throws IOException {&lt;br /&gt;
        return this;&lt;br /&gt;
    }&lt;br /&gt;
    public Writer append(char c) throws IOException {&lt;br /&gt;
        return this;&lt;br /&gt;
    }&lt;br /&gt;
    public void write(char cbuf[], int off, int len) throws IOException {&lt;br /&gt;
    }&lt;br /&gt;
    public void flush() throws IOException {&lt;br /&gt;
    }&lt;br /&gt;
    public void close() throws IOException {&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Provides Closable semantics ordinarily missing in a java.io.CharArrayWriter ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
/* Copyright (c) 2001-2009, The HSQL Development Group&lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions are met:&lt;br /&gt;
 *&lt;br /&gt;
 * Redistributions of source code must retain the above copyright notice, this&lt;br /&gt;
 * list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistributions in binary form must reproduce the above copyright notice,&lt;br /&gt;
 * this list of conditions and the following disclaimer in the documentation&lt;br /&gt;
 * and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 * Neither the name of the HSQL Development Group nor the names of its&lt;br /&gt;
 * contributors may be used to endorse or promote products derived from this&lt;br /&gt;
 * software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &amp;quot;AS IS&amp;quot;&lt;br /&gt;
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE&lt;br /&gt;
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE&lt;br /&gt;
 * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,&lt;br /&gt;
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;&lt;br /&gt;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND&lt;br /&gt;
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT&lt;br /&gt;
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
import java.io.CharArrayReader;&lt;br /&gt;
import java.io.CharArrayWriter;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.Writer;&lt;br /&gt;
/**&lt;br /&gt;
 * @todo - finer-grained synchronization to reduce average&lt;br /&gt;
 * potential monitor contention&lt;br /&gt;
 */&lt;br /&gt;
/**&lt;br /&gt;
 * Provides Closable semantics ordinarily missing in a&lt;br /&gt;
 * {@link java.io.CharArrayWriter}. &amp;lt;p&amp;gt;&lt;br /&gt;
 *&lt;br /&gt;
 * Accumulates output in a character array that automatically grows as needed.&amp;lt;p&amp;gt;&lt;br /&gt;
 *&lt;br /&gt;
 * Data is retrieved using &amp;lt;tt&amp;gt;toCharArray()&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;toCharArrayReader()&amp;lt;/tt&amp;gt;&lt;br /&gt;
 * and &amp;lt;tt&amp;gt;toString()&amp;lt;/tt&amp;gt;. &amp;lt;p&amp;gt;&lt;br /&gt;
 *&lt;br /&gt;
 * {@link #close() Closing} a &amp;lt;tt&amp;gt;ClosableCharArrayWriter&amp;lt;/tt&amp;gt; prevents&lt;br /&gt;
 * further write operations, but all other operations will succeed until after&lt;br /&gt;
 * the first invocation of {@link #free() free()}.&amp;lt;p&amp;gt;&lt;br /&gt;
 *&lt;br /&gt;
 * Freeing a &amp;lt;tt&amp;gt;ClosableCharArrayWriter&amp;lt;/tt&amp;gt; closes the writer and&lt;br /&gt;
 * releases its internal buffer, preventing successful invocation of all&lt;br /&gt;
 * operations, with the exception of &amp;lt;tt&amp;gt;size()&amp;lt;tt&amp;gt;, &amp;lt;tt&amp;gt;close()&amp;lt;/tt&amp;gt;,&lt;br /&gt;
 * &amp;lt;tt&amp;gt;isClosed()&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;free()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;isFreed()&amp;lt;/tt&amp;gt;. &amp;lt;p&amp;gt;&lt;br /&gt;
 *&lt;br /&gt;
 * This class is especially useful when an accumulating writer must be&lt;br /&gt;
 * handed off to an extenal client under contract that the writer should&lt;br /&gt;
 * exhibit true Closable behaviour, both in response to internally tracked&lt;br /&gt;
 * events and to client invocation of the &amp;lt;tt&amp;gt;Writer.close()&amp;lt;/tt&amp;gt; method.&lt;br /&gt;
 *&lt;br /&gt;
 * @author boucherb@users&lt;br /&gt;
 * @version 1.8.x&lt;br /&gt;
 * @since 1.8.x&lt;br /&gt;
 */&lt;br /&gt;
public class ClosableCharArrayWriter extends Writer {&lt;br /&gt;
    /**&lt;br /&gt;
     * Data buffer.&lt;br /&gt;
     */&lt;br /&gt;
    protected char[] buf;&lt;br /&gt;
    /**&lt;br /&gt;
     * # of valid characters in buffer.&lt;br /&gt;
     */&lt;br /&gt;
    protected int count;&lt;br /&gt;
    /**&lt;br /&gt;
     * Whether this writer is closed.&lt;br /&gt;
     */&lt;br /&gt;
    protected boolean closed;&lt;br /&gt;
    /**&lt;br /&gt;
     * Whether this writer is freed.&lt;br /&gt;
     */&lt;br /&gt;
    protected boolean freed;&lt;br /&gt;
    /**&lt;br /&gt;
     * Creates a new writer. &amp;lt;p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * The buffer capacity is initially 32 characters, although its size&lt;br /&gt;
     * automatically increases when necessary.&lt;br /&gt;
     */&lt;br /&gt;
    public ClosableCharArrayWriter() {&lt;br /&gt;
        this(32);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Creates a new writer with a buffer capacity of the specified&lt;br /&gt;
     * &amp;lt;tt&amp;gt;size&amp;lt;/tt&amp;gt;, in characters.&lt;br /&gt;
     *&lt;br /&gt;
     * @param size the initial size.&lt;br /&gt;
     * @exception IllegalArgumentException if &amp;lt;tt&amp;gt;size&amp;lt;/tt&amp;gt; is negative.&lt;br /&gt;
     */&lt;br /&gt;
    public ClosableCharArrayWriter(int size) throws IllegalArgumentException {&lt;br /&gt;
        if (size &amp;lt; 0) {&lt;br /&gt;
            throw new IllegalArgumentException(&amp;quot;Negative initial size: &amp;quot;&lt;br /&gt;
                                               + size);    // NOI18N&lt;br /&gt;
        }&lt;br /&gt;
        buf = new char[size];&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Writes the specified single character.&lt;br /&gt;
     *&lt;br /&gt;
     * @param c the single character to be written.&lt;br /&gt;
     * @throws java.io.IOException if an I/O error occurs.&lt;br /&gt;
     *      In particular, an &amp;lt;tt&amp;gt;IOException&amp;lt;/tt&amp;gt; may be thrown&lt;br /&gt;
     *      if this writer has been {@link #close() closed}.&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized void write(int c) throws IOException {&lt;br /&gt;
        checkClosed();&lt;br /&gt;
        int newcount = count + 1;&lt;br /&gt;
        if (newcount &amp;gt; buf.length) {&lt;br /&gt;
            buf = copyOf(buf, Math.max(buf.length &amp;lt;&amp;lt; 1, newcount));&lt;br /&gt;
        }&lt;br /&gt;
        buf[count] = (char) c;&lt;br /&gt;
        count      = newcount;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Writes the designated portion of the designated character array &amp;lt;p&amp;gt;.&lt;br /&gt;
     *&lt;br /&gt;
     * @param c the source character sequence.&lt;br /&gt;
     * @param off the start offset in the source character sequence.&lt;br /&gt;
     * @param len the number of characters to write.&lt;br /&gt;
     * @throws java.io.IOException if an I/O error occurs.&lt;br /&gt;
     *      In particular, an &amp;lt;tt&amp;gt;IOException&amp;lt;/tt&amp;gt; may be thrown&lt;br /&gt;
     *      if this writer has been {@link #close() closed}.&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized void write(char c[], int off,&lt;br /&gt;
                                   int len) throws IOException {&lt;br /&gt;
        checkClosed();&lt;br /&gt;
        if ((off &amp;lt; 0) || (off &amp;gt; c.length) || (len &amp;lt; 0)&lt;br /&gt;
                || ((off + len) &amp;gt; c.length) || ((off + len) &amp;lt; 0)) {&lt;br /&gt;
            throw new IndexOutOfBoundsException();&lt;br /&gt;
        } else if (len == 0) {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        int newcount = count + len;&lt;br /&gt;
        if (newcount &amp;gt; buf.length) {&lt;br /&gt;
            buf = copyOf(buf, Math.max(buf.length &amp;lt;&amp;lt; 1, newcount));&lt;br /&gt;
        }&lt;br /&gt;
        System.arraycopy(c, off, buf, count, len);&lt;br /&gt;
        count = newcount;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Efficiently writes the designated portion of the designated string. &amp;lt;p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * The operation occurs as if by calling&lt;br /&gt;
     * &amp;lt;tt&amp;gt;str.getChars(off, off + len, buf, count)&amp;lt;/tt&amp;gt;. &amp;lt;p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param str the string from which to write&lt;br /&gt;
     * @param off the start offset in the string.&lt;br /&gt;
     * @param len the number of characters to write.&lt;br /&gt;
     * @throws java.io.IOException if an I/O error occurs.&lt;br /&gt;
     *      In particular, an &amp;lt;tt&amp;gt;IOException&amp;lt;/tt&amp;gt; may be thrown&lt;br /&gt;
     *      if this writer has been {@link #close() closed}.&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized void write(String str, int off,&lt;br /&gt;
                                   int len) throws IOException {&lt;br /&gt;
        checkClosed();&lt;br /&gt;
        int strlen = str.length();&lt;br /&gt;
        if ((off &amp;lt; 0) || (off &amp;gt; strlen) || (len &amp;lt; 0) || ((off + len) &amp;gt; strlen)&lt;br /&gt;
                || ((off + len) &amp;lt; 0)) {&lt;br /&gt;
            throw new IndexOutOfBoundsException();&lt;br /&gt;
        } else if (len == 0) {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        int newcount = count + len;&lt;br /&gt;
        if (newcount &amp;gt; buf.length) {&lt;br /&gt;
            buf = copyOf(buf, Math.max(buf.length &amp;lt;&amp;lt; 1, newcount));&lt;br /&gt;
        }&lt;br /&gt;
        str.getChars(off, off + len, buf, count);&lt;br /&gt;
        count = newcount;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * By default, does nothing. &amp;lt;p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @throws java.io.IOException if an I/O error occurs.&lt;br /&gt;
     *      In particular, an &amp;lt;tt&amp;gt;IOException&amp;lt;/tt&amp;gt; may be thrown&lt;br /&gt;
     *      if this writer has been {@link #close() closed}.&lt;br /&gt;
     */&lt;br /&gt;
    public void flush() throws IOException {&lt;br /&gt;
        checkClosed();&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Writes the complete contents of this writer&amp;quot;s buffered data to the&lt;br /&gt;
     * specified writer. &amp;lt;p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * The operation occurs as if by calling &amp;lt;tt&amp;gt;out.write(buf, 0, count)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
     *&lt;br /&gt;
     * @param out the writer to which to write the data.&lt;br /&gt;
     * @throws java.io.IOException if an I/O error occurs.&lt;br /&gt;
     *      In particular, an &amp;lt;tt&amp;gt;IOException&amp;lt;/tt&amp;gt; may be thrown&lt;br /&gt;
     *      if this writer has been {@link #free() freed}.&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized void writeTo(Writer out) throws IOException {&lt;br /&gt;
        checkFreed();&lt;br /&gt;
        if (count &amp;gt; 0) {&lt;br /&gt;
            out.write(buf, 0, count);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Returns the current capacity of this writer&amp;quot;s data buffer.&lt;br /&gt;
     *&lt;br /&gt;
     * @return  the current capacity (the length of the internal&lt;br /&gt;
     *          data array)&lt;br /&gt;
     * @throws java.io.IOException if an I/O error occurs.&lt;br /&gt;
     *      In particular, an &amp;lt;tt&amp;gt;IOException&amp;lt;/tt&amp;gt; may be thrown&lt;br /&gt;
     *      if this writer has been {@link #free() freed}.&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized int capacity() throws IOException {&lt;br /&gt;
        checkFreed();&lt;br /&gt;
        return buf.length;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Resets the &amp;lt;tt&amp;gt;count&amp;lt;/tt&amp;gt; field of this writer to zero, so that all&lt;br /&gt;
     * currently accumulated output is effectively discarded. Further write&lt;br /&gt;
     * operations will reuse the allocated buffer space.&lt;br /&gt;
     *&lt;br /&gt;
     * @see #count&lt;br /&gt;
     * @throws java.io.IOException if an I/O error occurs.&lt;br /&gt;
     *      In particular, an &amp;lt;tt&amp;gt;IOException&amp;lt;/tt&amp;gt; may be thrown&lt;br /&gt;
     *      if this output stream has been {@link #close() closed}.&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized void reset() throws IOException {&lt;br /&gt;
        checkClosed();&lt;br /&gt;
        count = 0;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Attempts to reduce this writer&amp;quot;s buffer capacity to its current size. &amp;lt;p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * If the buffer is larger than necessary to hold its current sequence of&lt;br /&gt;
     * characters, then it may be resized to become more space efficient.&lt;br /&gt;
     * Calling this method may, but is not required to, affect the value&lt;br /&gt;
     * returned by a subsequent call to the {@link #capacity()} method.&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized void trimToSize() throws IOException {&lt;br /&gt;
        checkFreed();&lt;br /&gt;
        if (buf.length &amp;gt; count) {&lt;br /&gt;
            buf = copyOf(buf, count);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Creates a newly allocated character array. Its size is the current&lt;br /&gt;
     * size of this writer and the valid contents of the buffer&lt;br /&gt;
     * have been copied into it.&lt;br /&gt;
     *&lt;br /&gt;
     * @return the current contents of this writer, as a character array.&lt;br /&gt;
     * @see #size()&lt;br /&gt;
     * @throws java.io.IOException if an I/O error occurs.&lt;br /&gt;
     *      In particular, an &amp;lt;tt&amp;gt;IOException&amp;lt;/tt&amp;gt; may be thrown&lt;br /&gt;
     *      if this writer has been {@link #free() freed}.&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized char[] toCharArray() throws IOException {&lt;br /&gt;
        checkFreed();&lt;br /&gt;
        return copyOf(buf, count);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Returns the current size of this writer&amp;quot;s accumulated character data.&lt;br /&gt;
     *&lt;br /&gt;
     * @return the value of the &amp;lt;tt&amp;gt;count&amp;lt;/tt&amp;gt; field, which is the number&lt;br /&gt;
     *      of valid characters accumulated in this writer.&lt;br /&gt;
     * @see #count&lt;br /&gt;
     * @throws java.io.IOException never&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized int size() throws IOException {&lt;br /&gt;
        return count;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Sets the size of this writer&amp;quot;s accumulated character data. &amp;lt;p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param   newSize the new size of this writer&amp;quot;s accumulated data&lt;br /&gt;
     * @throws  ArrayIndexOutOfBoundsException if new size is negative&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized void setSize(int newSize) {&lt;br /&gt;
        if (newSize &amp;lt; 0) {&lt;br /&gt;
            throw new ArrayIndexOutOfBoundsException(newSize);&lt;br /&gt;
        } else if (newSize &amp;gt; buf.length) {&lt;br /&gt;
            buf = copyOf(buf, Math.max(buf.length &amp;lt;&amp;lt; 1, newSize));&lt;br /&gt;
        }&lt;br /&gt;
        count = newSize;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Performs an effecient (zero-copy) conversion of the character data&lt;br /&gt;
     * accumulated in this writer to a reader. &amp;lt;p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * To ensure the integrity of the resulting reader, {@link #free()&lt;br /&gt;
     * free} is invoked upon this writer as a side-effect.&lt;br /&gt;
     *&lt;br /&gt;
     * @return a reader representing this writer&amp;quot;s accumulated&lt;br /&gt;
     *      character data&lt;br /&gt;
     * @throws java.io.IOException if an I/O error occurs.&lt;br /&gt;
     *      In particular, an &amp;lt;tt&amp;gt;IOException&amp;lt;/tt&amp;gt; may be thrown&lt;br /&gt;
     *      if this writer has been {@link #free() freed}.&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized CharArrayReader toCharArrayReader()&lt;br /&gt;
    throws IOException {&lt;br /&gt;
        checkFreed();&lt;br /&gt;
        CharArrayReader reader = new CharArrayReader(buf, 0, count);&lt;br /&gt;
        //System.out.println(&amp;quot;toCharArrayReader::buf.length: &amp;quot; + buf.length);&lt;br /&gt;
        free();&lt;br /&gt;
        return reader;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Converts this writer&amp;quot;s accumulated data into a string.&lt;br /&gt;
     *&lt;br /&gt;
     * @return String constructed from this writer&amp;quot;s accumulated data&lt;br /&gt;
     * @throws RuntimeException may be thrown if this writer has been&lt;br /&gt;
     *      {@link #free() freed}.&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized String toString() {&lt;br /&gt;
        try {&lt;br /&gt;
            checkFreed();&lt;br /&gt;
        } catch (IOException ex) {&lt;br /&gt;
            throw new RuntimeException(ex.toString());&lt;br /&gt;
        }&lt;br /&gt;
        return new String(buf, 0, count);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Closes this object for further writing. &amp;lt;p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * Other operations may continue to succeed until after the first invocation&lt;br /&gt;
     * of {@link #free() free()}. &amp;lt;p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @throws java.io.IOException if an I/O error occurs (default: never)&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized void close() throws IOException {&lt;br /&gt;
        closed = true;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * @return &amp;lt;tt&amp;gt;true&amp;lt;/tt&amp;gt; if this writer is closed, else &amp;lt;tt&amp;gt;false&amp;lt;/tt&amp;gt;&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized boolean isClosed() {&lt;br /&gt;
        return closed;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Closes this object and releases the underlying buffer for&lt;br /&gt;
     * garbage collection. &amp;lt;p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @throws java.io.IOException if an I/O error occurs while closing&lt;br /&gt;
     *      this writer (default: never).&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized void free() throws IOException {&lt;br /&gt;
        closed = true;&lt;br /&gt;
        freed  = true;&lt;br /&gt;
        buf    = null;&lt;br /&gt;
        count  = 0;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * @return &amp;lt;tt&amp;gt;true&amp;lt;/tt&amp;gt; if this writer is freed; else &amp;lt;tt&amp;gt;false&amp;lt;/tt&amp;gt;.&lt;br /&gt;
     */&lt;br /&gt;
    public synchronized boolean isFreed() {&lt;br /&gt;
        return freed;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * @throws java.io.IOException if this writer is closed.&lt;br /&gt;
     */&lt;br /&gt;
    protected synchronized void checkClosed() throws IOException {&lt;br /&gt;
        if (closed) {&lt;br /&gt;
            throw new IOException(&amp;quot;writer is closed.&amp;quot;);    // NOI18N&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * @throws java.io.IOException if this writer is freed.&lt;br /&gt;
     */&lt;br /&gt;
    protected synchronized void checkFreed() throws IOException {&lt;br /&gt;
        if (freed) {&lt;br /&gt;
            throw new IOException(&amp;quot;write buffer is freed.&amp;quot;);    // NOI18N&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Retrieves a copy of &amp;lt;tt&amp;gt;original&amp;lt;/tt&amp;gt; with the given&lt;br /&gt;
     * &amp;lt;tt&amp;gt;newLength&amp;lt;/tt&amp;gt;. &amp;lt;p&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @param original the object to copy&lt;br /&gt;
     * @param newLength the length of the copy&lt;br /&gt;
     * @return copy of &amp;lt;tt&amp;gt;original&amp;lt;/tt&amp;gt; with the given &amp;lt;tt&amp;gt;newLength&amp;lt;/tt&amp;gt;&lt;br /&gt;
     */&lt;br /&gt;
    protected char[] copyOf(char[] original, int newLength) {&lt;br /&gt;
        char[] copy = new char[newLength];&lt;br /&gt;
        System.arraycopy(original, 0, copy, 0,&lt;br /&gt;
                         Math.min(original.length, newLength));&lt;br /&gt;
        return copy;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Reads characters available from the Reader and returns these characters as a String object. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Copyright Aduna (http://www.aduna-software.ru/) (c) 1997-2006.&lt;br /&gt;
 *&lt;br /&gt;
 * Licensed under the Aduna BSD-style license.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.CharArrayWriter;&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileWriter;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.Reader;&lt;br /&gt;
import java.io.Writer;&lt;br /&gt;
public class Main {&lt;br /&gt;
  /**&lt;br /&gt;
   * Fully reads the characters available from the supplied Reader&lt;br /&gt;
   * and returns these characters as a String object.&lt;br /&gt;
   *&lt;br /&gt;
   * @param reader The Reader to read the characters from.&lt;br /&gt;
   * @return A String existing of the characters that were read.&lt;br /&gt;
   * @throws IOException If I/O error occurred.&lt;br /&gt;
   */&lt;br /&gt;
  public static final String readFully(Reader reader)&lt;br /&gt;
    throws IOException&lt;br /&gt;
  {&lt;br /&gt;
    CharArrayWriter out = new CharArrayWriter(4096);&lt;br /&gt;
    transfer(reader, out);&lt;br /&gt;
    out.close();&lt;br /&gt;
    return out.toString();&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Transfers all characters that can be read from &amp;lt;tt&amp;gt;in&amp;lt;/tt&amp;gt; to&lt;br /&gt;
   * &amp;lt;tt&amp;gt;out&amp;lt;/tt&amp;gt;.&lt;br /&gt;
   *&lt;br /&gt;
   * @param in The Reader to read characters from.&lt;br /&gt;
   * @param out The Writer to write characters to.&lt;br /&gt;
   * @return The total number of characters transfered.&lt;br /&gt;
   */&lt;br /&gt;
  public static final long transfer(Reader in, Writer out)&lt;br /&gt;
    throws IOException&lt;br /&gt;
  {&lt;br /&gt;
    long totalChars = 0;&lt;br /&gt;
    int charsInBuf = 0;&lt;br /&gt;
    char[] buf = new char[4096];&lt;br /&gt;
    while ((charsInBuf = in.read(buf)) != -1) {&lt;br /&gt;
      out.write(buf, 0, charsInBuf);&lt;br /&gt;
      totalChars += charsInBuf;&lt;br /&gt;
    }&lt;br /&gt;
    return totalChars;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== String Buffer Writer ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
// &lt;br /&gt;
// $Id: StringBufferWriter.java,v 1.4 2004/05/09 20:33:04 gregwilkins Exp $&lt;br /&gt;
// Copyright 2001-2004 Mort Bay Consulting Pty. Ltd.&lt;br /&gt;
// ------------------------------------------------------------------------&lt;br /&gt;
// Licensed under the Apache License, Version 2.0 (the &amp;quot;License&amp;quot;);&lt;br /&gt;
// you may not use this file except in compliance with the License.&lt;br /&gt;
// You may obtain a copy of the License at &lt;br /&gt;
// http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
// Unless required by applicable law or agreed to in writing, software&lt;br /&gt;
// distributed under the License is distributed on an &amp;quot;AS IS&amp;quot; BASIS,&lt;br /&gt;
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&lt;br /&gt;
// See the License for the specific language governing permissions and&lt;br /&gt;
// limitations under the License.&lt;br /&gt;
// &lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.Writer;&lt;br /&gt;
&lt;br /&gt;
/* ------------------------------------------------------------ */&lt;br /&gt;
/** A Writer to a StringBuffer.&lt;br /&gt;
 *&lt;br /&gt;
 * @version $Id: StringBufferWriter.java,v 1.4 2004/05/09 20:33:04 gregwilkins Exp $&lt;br /&gt;
 * @author Greg Wilkins (gregw)&lt;br /&gt;
 */&lt;br /&gt;
public class StringBufferWriter extends Writer&lt;br /&gt;
{&lt;br /&gt;
    /* ------------------------------------------------------------ */&lt;br /&gt;
    private StringBuffer _buffer;&lt;br /&gt;
    /* ------------------------------------------------------------ */&lt;br /&gt;
    /** Constructor. &lt;br /&gt;
     */&lt;br /&gt;
    public StringBufferWriter()&lt;br /&gt;
    {&lt;br /&gt;
        _buffer=new StringBuffer();&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    /* ------------------------------------------------------------ */&lt;br /&gt;
    /** Constructor. &lt;br /&gt;
     * @param buffer &lt;br /&gt;
     */&lt;br /&gt;
    public StringBufferWriter(StringBuffer buffer)&lt;br /&gt;
    {&lt;br /&gt;
        _buffer=buffer;&lt;br /&gt;
    }&lt;br /&gt;
    /* ------------------------------------------------------------ */&lt;br /&gt;
    public void setStringBuffer(StringBuffer buffer)&lt;br /&gt;
    {&lt;br /&gt;
        _buffer=buffer;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    /* ------------------------------------------------------------ */&lt;br /&gt;
    public StringBuffer getStringBuffer()&lt;br /&gt;
    {&lt;br /&gt;
        return _buffer;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    /* ------------------------------------------------------------ */&lt;br /&gt;
    public void write(char c)&lt;br /&gt;
        throws IOException&lt;br /&gt;
    {&lt;br /&gt;
        _buffer.append(c);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    /* ------------------------------------------------------------ */&lt;br /&gt;
    public void write(char[] ca)&lt;br /&gt;
        throws IOException&lt;br /&gt;
    {&lt;br /&gt;
        _buffer.append(ca);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    /* ------------------------------------------------------------ */&lt;br /&gt;
    public void write(char[] ca,int offset, int length)&lt;br /&gt;
        throws IOException&lt;br /&gt;
    {&lt;br /&gt;
        _buffer.append(ca,offset,length);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    /* ------------------------------------------------------------ */&lt;br /&gt;
    public void write(String s)&lt;br /&gt;
        throws IOException&lt;br /&gt;
    {&lt;br /&gt;
        _buffer.append(s);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    /* ------------------------------------------------------------ */&lt;br /&gt;
    public void write(String s,int offset, int length)&lt;br /&gt;
        throws IOException&lt;br /&gt;
    {&lt;br /&gt;
        for (int i=0;i&amp;lt;length;i++)&lt;br /&gt;
            _buffer.append(s.charAt(offset+i));&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    /* ------------------------------------------------------------ */&lt;br /&gt;
    public void flush()&lt;br /&gt;
    {}&lt;br /&gt;
    /* ------------------------------------------------------------ */&lt;br /&gt;
    public void reset()&lt;br /&gt;
    {&lt;br /&gt;
        _buffer.setLength(0);&lt;br /&gt;
    }&lt;br /&gt;
    /* ------------------------------------------------------------ */&lt;br /&gt;
    public void close()&lt;br /&gt;
    {}&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Writes all characters from a Reader to a file using the default character encoding. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Copyright Aduna (http://www.aduna-software.ru/) (c) 1997-2006.&lt;br /&gt;
 *&lt;br /&gt;
 * Licensed under the Aduna BSD-style license.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileWriter;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.Reader;&lt;br /&gt;
import java.io.Writer;&lt;br /&gt;
public class Main {&lt;br /&gt;
  &lt;br /&gt;
  /**&lt;br /&gt;
   * Writes all characters from a &amp;lt;tt&amp;gt;Reader&amp;lt;/tt&amp;gt; to a file using the default&lt;br /&gt;
   * character encoding.&lt;br /&gt;
   *&lt;br /&gt;
   * @param reader The &amp;lt;tt&amp;gt;Reader&amp;lt;/tt&amp;gt; containing the data to write to the&lt;br /&gt;
   * file.&lt;br /&gt;
   * @param file The file to write the data to.&lt;br /&gt;
   * @return The total number of characters written.&lt;br /&gt;
   * @throws IOException If an I/O error occured while trying to write the&lt;br /&gt;
   * data to the file.&lt;br /&gt;
   * @see java.io.FileWriter&lt;br /&gt;
   */&lt;br /&gt;
  public static final long writeToFile(Reader reader, File file)&lt;br /&gt;
    throws IOException&lt;br /&gt;
  {&lt;br /&gt;
    FileWriter writer = new FileWriter(file);&lt;br /&gt;
    try {&lt;br /&gt;
      return transfer(reader, writer);&lt;br /&gt;
    }&lt;br /&gt;
    finally {&lt;br /&gt;
      writer.close();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Transfers all characters that can be read from &amp;lt;tt&amp;gt;in&amp;lt;/tt&amp;gt; to&lt;br /&gt;
   * &amp;lt;tt&amp;gt;out&amp;lt;/tt&amp;gt;.&lt;br /&gt;
   *&lt;br /&gt;
   * @param in The Reader to read characters from.&lt;br /&gt;
   * @param out The Writer to write characters to.&lt;br /&gt;
   * @return The total number of characters transfered.&lt;br /&gt;
   */&lt;br /&gt;
  public static final long transfer(Reader in, Writer out)&lt;br /&gt;
    throws IOException&lt;br /&gt;
  {&lt;br /&gt;
    long totalChars = 0;&lt;br /&gt;
    int charsInBuf = 0;&lt;br /&gt;
    char[] buf = new char[4096];&lt;br /&gt;
    while ((charsInBuf = in.read(buf)) != -1) {&lt;br /&gt;
      out.write(buf, 0, charsInBuf);&lt;br /&gt;
      totalChars += charsInBuf;&lt;br /&gt;
    }&lt;br /&gt;
    return totalChars;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Write the entire contents of the supplied string to the given writer. This method always flushes and closes the writer when finished. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * JBoss DNA (http://www.jboss.org/dna)&lt;br /&gt;
 * See the COPYRIGHT.txt file distributed with this work for information&lt;br /&gt;
 * regarding copyright ownership.  Some portions may be licensed&lt;br /&gt;
 * to Red Hat, Inc. under one or more contributor license agreements.&lt;br /&gt;
 * See the AUTHORS.txt file in the distribution for a full listing of &lt;br /&gt;
 * individual contributors. &lt;br /&gt;
 *&lt;br /&gt;
 * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA&lt;br /&gt;
 * is licensed to you under the terms of the GNU Lesser General Public License as&lt;br /&gt;
 * published by the Free Software Foundation; either version 2.1 of&lt;br /&gt;
 * the License, or (at your option) any later version.&lt;br /&gt;
 *&lt;br /&gt;
 * JBoss DNA is distributed in the hope that it will be useful,&lt;br /&gt;
 * but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU&lt;br /&gt;
 * Lesser General Public License for more details.&lt;br /&gt;
 *&lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
 * License along with this software; if not, write to the Free&lt;br /&gt;
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA&lt;br /&gt;
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.io.OutputStream;&lt;br /&gt;
import java.io.Reader;&lt;br /&gt;
import java.io.Writer;&lt;br /&gt;
/**&lt;br /&gt;
 * @author Randall Hauch&lt;br /&gt;
 */&lt;br /&gt;
public class Main {&lt;br /&gt;
  /**&lt;br /&gt;
   * Write the entire contents of the supplied string to the given writer. This method always flushes and closes the writer when&lt;br /&gt;
   * finished.&lt;br /&gt;
   * &lt;br /&gt;
   * @param input the content to write to the writer; may be null&lt;br /&gt;
   * @param writer the writer to which the content is to be written&lt;br /&gt;
   * @throws IOException&lt;br /&gt;
   * @throws IllegalArgumentException if the writer is null&lt;br /&gt;
   */&lt;br /&gt;
  public static void write( Reader input,&lt;br /&gt;
                            Writer writer ) throws IOException {&lt;br /&gt;
      boolean error = false;&lt;br /&gt;
      try {&lt;br /&gt;
          if (input != null) {&lt;br /&gt;
              char[] buffer = new char[1024];&lt;br /&gt;
              try {&lt;br /&gt;
                  int numRead = 0;&lt;br /&gt;
                  while ((numRead = input.read(buffer)) &amp;gt; -1) {&lt;br /&gt;
                      writer.write(buffer, 0, numRead);&lt;br /&gt;
                  }&lt;br /&gt;
              } finally {&lt;br /&gt;
                  input.close();&lt;br /&gt;
              }&lt;br /&gt;
          }&lt;br /&gt;
      } catch (IOException e) {&lt;br /&gt;
          error = true; // this error should be thrown, even if there is an error flushing/closing writer&lt;br /&gt;
          throw e;&lt;br /&gt;
      } catch (RuntimeException e) {&lt;br /&gt;
          error = true; // this error should be thrown, even if there is an error flushing/closing writer&lt;br /&gt;
          throw e;&lt;br /&gt;
      } finally {&lt;br /&gt;
          try {&lt;br /&gt;
              writer.flush();&lt;br /&gt;
          } catch (IOException e) {&lt;br /&gt;
              if (!error) throw e;&lt;br /&gt;
          } finally {&lt;br /&gt;
              try {&lt;br /&gt;
                  writer.close();&lt;br /&gt;
              } catch (IOException e) {&lt;br /&gt;
                  if (!error) throw e;&lt;br /&gt;
              }&lt;br /&gt;
          }&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>