<?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%2FFile_Writer</id>
		<title>Java/File Input Output/File 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%2FFile_Writer"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/File_Input_Output/File_Writer&amp;action=history"/>
		<updated>2026-04-22T22:19:40Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/File_Input_Output/File_Writer&amp;diff=6257&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/File_Writer&amp;diff=6257&amp;oldid=prev"/>
				<updated>2010-06-01T06:05:16Z</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:05, 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/File_Writer&amp;diff=6256&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/File_Writer&amp;diff=6256&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;== Append or add some contents to the file ==&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;
import java.io.File;&lt;br /&gt;
import java.io.FileWriter;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] args) throws Exception{&lt;br /&gt;
    File file = new File(&amp;quot;user.txt&amp;quot;);&lt;br /&gt;
    FileWriter writer = new FileWriter(file, true);&lt;br /&gt;
    writer.write(&amp;quot;username=java;password=secret&amp;quot; + System.getProperty(&amp;quot;line.separator&amp;quot;));&lt;br /&gt;
    writer.flush();&lt;br /&gt;
    writer.close();&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;
== Demonstrate FileWriter. ==&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;
import java.io.FileWriter;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
class FileWriterDemo {&lt;br /&gt;
  public static void main(String args[]) throws IOException {&lt;br /&gt;
    String source = &amp;quot;test&amp;quot;;&lt;br /&gt;
    char buffer[] = new char[source.length()];&lt;br /&gt;
    source.getChars(0, source.length(), buffer, 0);&lt;br /&gt;
    FileWriter f0 = new FileWriter(&amp;quot;file1.txt&amp;quot;);&lt;br /&gt;
    for (int i = 0; i &amp;lt; buffer.length; i += 2) {&lt;br /&gt;
      f0.write(buffer[i]);&lt;br /&gt;
    }&lt;br /&gt;
    f0.close();&lt;br /&gt;
    FileWriter f1 = new FileWriter(&amp;quot;file2.txt&amp;quot;);&lt;br /&gt;
    f1.write(buffer);&lt;br /&gt;
    f1.close();&lt;br /&gt;
    FileWriter f2 = new FileWriter(&amp;quot;file3.txt&amp;quot;);&lt;br /&gt;
    f2.write(buffer, buffer.length - buffer.length / 4, buffer.length / 4);&lt;br /&gt;
    f2.close();&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;
== Implementation of a fast 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;
/*&lt;br /&gt;
 * Licensed to the Apache Software Foundation (ASF) under one&lt;br /&gt;
 * or more contributor license agreements.  See the NOTICE file&lt;br /&gt;
 * distributed with this work for additional information&lt;br /&gt;
 * regarding copyright ownership.  The ASF licenses this file&lt;br /&gt;
 * to you under the Apache License, Version 2.0 (the&lt;br /&gt;
 * &amp;quot;License&amp;quot;); you may not use this file except in compliance&lt;br /&gt;
 * with the License.  You may obtain a copy of the License at&lt;br /&gt;
 *&lt;br /&gt;
 *   http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
 *&lt;br /&gt;
 * Unless required by applicable law or agreed to in writing,&lt;br /&gt;
 * software distributed under the License is distributed on an&lt;br /&gt;
 * &amp;quot;AS IS&amp;quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY&lt;br /&gt;
 * KIND, either express or implied.  See the License for the&lt;br /&gt;
 * specific language governing permissions and limitations&lt;br /&gt;
 * 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;
 * Implementation of a fast Writer. It was originally taken from JspWriter&lt;br /&gt;
 * and modified to have less syncronization going on.&lt;br /&gt;
 *&lt;br /&gt;
 * @author &lt;br /&gt;
 * @author Anil K. Vijendran&lt;br /&gt;
 * @version $Id: VelocityWriter.java 463298 2006-10-12 16:10:32Z henning $&lt;br /&gt;
 */&lt;br /&gt;
public final class VelocityWriter extends Writer&lt;br /&gt;
{&lt;br /&gt;
    /**&lt;br /&gt;
     * constant indicating that the Writer is not buffering output&lt;br /&gt;
     */&lt;br /&gt;
    public static final int NO_BUFFER = 0;&lt;br /&gt;
    /**&lt;br /&gt;
     * constant indicating that the Writer is buffered and is using the&lt;br /&gt;
     * implementation default buffer size&lt;br /&gt;
     */&lt;br /&gt;
    public static final int DEFAULT_BUFFER = -1;&lt;br /&gt;
    /**&lt;br /&gt;
     * constant indicating that the Writer is buffered and is unbounded;&lt;br /&gt;
     * this is used in BodyContent&lt;br /&gt;
     */&lt;br /&gt;
    public static final int UNBOUNDED_BUFFER = -2;&lt;br /&gt;
    private int     bufferSize;&lt;br /&gt;
    private boolean autoFlush;&lt;br /&gt;
    private Writer writer;&lt;br /&gt;
    private char cb[];&lt;br /&gt;
    private int nextChar;&lt;br /&gt;
    private static int defaultCharBufferSize = 8 * 1024;&lt;br /&gt;
    /**&lt;br /&gt;
     * Create a buffered character-output stream that uses a default-sized&lt;br /&gt;
     * output buffer.&lt;br /&gt;
     *&lt;br /&gt;
     * @param  writer  Writer to wrap around&lt;br /&gt;
     */&lt;br /&gt;
    public VelocityWriter(Writer writer)&lt;br /&gt;
    {&lt;br /&gt;
        this(writer, defaultCharBufferSize, true);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * private constructor.&lt;br /&gt;
     */&lt;br /&gt;
    private VelocityWriter(int bufferSize, boolean autoFlush)&lt;br /&gt;
    {&lt;br /&gt;
        this.bufferSize = bufferSize;&lt;br /&gt;
        this.autoFlush  = autoFlush;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * This method returns the size of the buffer used by the JspWriter.&lt;br /&gt;
     *&lt;br /&gt;
     * @return the size of the buffer in bytes, or 0 is unbuffered.&lt;br /&gt;
     */&lt;br /&gt;
    public int getBufferSize() { return bufferSize; }&lt;br /&gt;
    /**&lt;br /&gt;
     * This method indicates whether the JspWriter is autoFlushing.&lt;br /&gt;
     *&lt;br /&gt;
     * @return if this JspWriter is auto flushing or throwing IOExceptions on&lt;br /&gt;
     *         buffer overflow conditions&lt;br /&gt;
     */&lt;br /&gt;
    public boolean isAutoFlush() { return autoFlush; }&lt;br /&gt;
    /**&lt;br /&gt;
     * Create a new buffered character-output stream that uses an output&lt;br /&gt;
     * buffer of the given size.&lt;br /&gt;
     *&lt;br /&gt;
     * @param  writer  Writer to wrap around&lt;br /&gt;
     * @param  sz     Output-buffer size, a positive integer&lt;br /&gt;
     * @param autoFlush&lt;br /&gt;
     *&lt;br /&gt;
     * @exception  IllegalArgumentException  If sz is &amp;lt;= 0&lt;br /&gt;
     */&lt;br /&gt;
    public VelocityWriter(Writer writer, int sz, boolean autoFlush)&lt;br /&gt;
    {&lt;br /&gt;
        this(sz, autoFlush);&lt;br /&gt;
        if (sz &amp;lt; 0)&lt;br /&gt;
            throw new IllegalArgumentException(&amp;quot;Buffer size &amp;lt;= 0&amp;quot;);&lt;br /&gt;
        this.writer = writer;&lt;br /&gt;
        cb = sz == 0 ? null : new char[sz];&lt;br /&gt;
        nextChar = 0;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Flush the output buffer to the underlying character stream, without&lt;br /&gt;
     * flushing the stream itself.  This method is non-private only so that it&lt;br /&gt;
     * may be invoked by PrintStream.&lt;br /&gt;
     */&lt;br /&gt;
    private final void flushBuffer() throws IOException&lt;br /&gt;
    {&lt;br /&gt;
        if (bufferSize == 0)&lt;br /&gt;
            return;&lt;br /&gt;
        if (nextChar == 0)&lt;br /&gt;
            return;&lt;br /&gt;
        writer.write(cb, 0, nextChar);&lt;br /&gt;
        nextChar = 0;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Discard the output buffer.&lt;br /&gt;
     */&lt;br /&gt;
    public final void clear()&lt;br /&gt;
    {&lt;br /&gt;
        nextChar = 0;&lt;br /&gt;
    }&lt;br /&gt;
    private final void bufferOverflow() throws IOException&lt;br /&gt;
    {&lt;br /&gt;
        throw new IOException(&amp;quot;overflow&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Flush the stream.&lt;br /&gt;
     * @throws IOException&lt;br /&gt;
     *&lt;br /&gt;
     */&lt;br /&gt;
    public final void flush()  throws IOException&lt;br /&gt;
    {&lt;br /&gt;
        flushBuffer();&lt;br /&gt;
        if (writer != null)&lt;br /&gt;
        {&lt;br /&gt;
            writer.flush();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Close the stream.&lt;br /&gt;
     * @throws IOException&lt;br /&gt;
     *&lt;br /&gt;
     */&lt;br /&gt;
    public final void close() throws IOException {&lt;br /&gt;
        if (writer == null)&lt;br /&gt;
            return;&lt;br /&gt;
        flush();&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * @return the number of bytes unused in the buffer&lt;br /&gt;
     */&lt;br /&gt;
    public final int getRemaining()&lt;br /&gt;
    {&lt;br /&gt;
        return bufferSize - nextChar;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Write a single character.&lt;br /&gt;
     * @param c&lt;br /&gt;
     * @throws IOException&lt;br /&gt;
     *&lt;br /&gt;
     */&lt;br /&gt;
    public final void write(int c) throws IOException&lt;br /&gt;
    {&lt;br /&gt;
        if (bufferSize == 0)&lt;br /&gt;
        {&lt;br /&gt;
            writer.write(c);&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            if (nextChar &amp;gt;= bufferSize)&lt;br /&gt;
                if (autoFlush)&lt;br /&gt;
                    flushBuffer();&lt;br /&gt;
                else&lt;br /&gt;
                    bufferOverflow();&lt;br /&gt;
            cb[nextChar++] = (char) c;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Our own little min method, to avoid loading&lt;br /&gt;
     * &amp;lt;code&amp;gt;java.lang.Math&amp;lt;/code&amp;gt; if we&amp;quot;ve run out of file&lt;br /&gt;
     * descriptors and we&amp;quot;re trying to print a stack trace.&lt;br /&gt;
     */&lt;br /&gt;
    private final int min(int a, int b)&lt;br /&gt;
    {&lt;br /&gt;
      return (a &amp;lt; b ? a : b);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Write a portion of an array of characters.&lt;br /&gt;
     *&lt;br /&gt;
     * &amp;lt;p&amp;gt; Ordinarily this method stores characters from the given array into&lt;br /&gt;
     * this stream&amp;quot;s buffer, flushing the buffer to the underlying stream as&lt;br /&gt;
     * needed.  If the requested length is at least as large as the buffer,&lt;br /&gt;
     * however, then this method will flush the buffer and write the characters&lt;br /&gt;
     * directly to the underlying stream.  Thus redundant&lt;br /&gt;
     * &amp;lt;code&amp;gt;DiscardableBufferedWriter&amp;lt;/code&amp;gt;s will not copy data unnecessarily.&lt;br /&gt;
     *&lt;br /&gt;
     * @param  cbuf  A character array&lt;br /&gt;
     * @param  off   Offset from which to start reading characters&lt;br /&gt;
     * @param  len   Number of characters to write&lt;br /&gt;
     * @throws IOException&lt;br /&gt;
     *&lt;br /&gt;
     */&lt;br /&gt;
    public final void write(char cbuf[], int off, int len)&lt;br /&gt;
        throws IOException&lt;br /&gt;
    {&lt;br /&gt;
        if (bufferSize == 0)&lt;br /&gt;
        {&lt;br /&gt;
            writer.write(cbuf, off, len);&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if (len == 0)&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if (len &amp;gt;= bufferSize)&lt;br /&gt;
        {&lt;br /&gt;
            /* If the request length exceeds the size of the output buffer,&lt;br /&gt;
            flush the buffer and then write the data directly.  In this&lt;br /&gt;
            way buffered streams will cascade harmlessly. */&lt;br /&gt;
            if (autoFlush)&lt;br /&gt;
                flushBuffer();&lt;br /&gt;
            else&lt;br /&gt;
                bufferOverflow();&lt;br /&gt;
                writer.write(cbuf, off, len);&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        int b = off, t = off + len;&lt;br /&gt;
        while (b &amp;lt; t)&lt;br /&gt;
        {&lt;br /&gt;
            int d = min(bufferSize - nextChar, t - b);&lt;br /&gt;
            System.arraycopy(cbuf, b, cb, nextChar, d);&lt;br /&gt;
            b += d;&lt;br /&gt;
            nextChar += d;&lt;br /&gt;
            if (nextChar &amp;gt;= bufferSize)&lt;br /&gt;
                if (autoFlush)&lt;br /&gt;
                    flushBuffer();&lt;br /&gt;
                else&lt;br /&gt;
                    bufferOverflow();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Write an array of characters.  This method cannot be inherited from the&lt;br /&gt;
     * Writer class because it must suppress I/O exceptions.&lt;br /&gt;
     * @param buf&lt;br /&gt;
     * @throws IOException&lt;br /&gt;
     */&lt;br /&gt;
    public final void write(char buf[]) throws IOException&lt;br /&gt;
    {&lt;br /&gt;
      write(buf, 0, buf.length);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Write a portion of a String.&lt;br /&gt;
     *&lt;br /&gt;
     * @param  s     String to be written&lt;br /&gt;
     * @param  off   Offset from which to start reading characters&lt;br /&gt;
     * @param  len   Number of characters to be written&lt;br /&gt;
     * @throws IOException&lt;br /&gt;
     *&lt;br /&gt;
     */&lt;br /&gt;
    public final void write(String s, int off, int len) throws IOException&lt;br /&gt;
    {&lt;br /&gt;
        if (bufferSize == 0)&lt;br /&gt;
        {&lt;br /&gt;
            writer.write(s, off, len);&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        int b = off, t = off + len;&lt;br /&gt;
        while (b &amp;lt; t)&lt;br /&gt;
        {&lt;br /&gt;
            int d = min(bufferSize - nextChar, t - b);&lt;br /&gt;
            s.getChars(b, b + d, cb, nextChar);&lt;br /&gt;
            b += d;&lt;br /&gt;
            nextChar += d;&lt;br /&gt;
            if (nextChar &amp;gt;= bufferSize)&lt;br /&gt;
                if (autoFlush)&lt;br /&gt;
                    flushBuffer();&lt;br /&gt;
                else&lt;br /&gt;
                    bufferOverflow();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Write a string.  This method cannot be inherited from the Writer class&lt;br /&gt;
     * because it must suppress I/O exceptions.&lt;br /&gt;
     * @param s&lt;br /&gt;
     * @throws IOException&lt;br /&gt;
     */&lt;br /&gt;
    public final void write(String s) throws IOException&lt;br /&gt;
    {&lt;br /&gt;
        if (s != null)&lt;br /&gt;
        {&lt;br /&gt;
            write(s, 0, s.length());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * resets this class so that it can be reused&lt;br /&gt;
     * @param writer&lt;br /&gt;
     *&lt;br /&gt;
     */&lt;br /&gt;
    public final void recycle(Writer writer)&lt;br /&gt;
    {&lt;br /&gt;
        this.writer = writer;&lt;br /&gt;
        clear();&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;
== Use FileWriter to write an array of strings to a file. ==&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;
import java.io.FileWriter;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] argv) throws Exception {&lt;br /&gt;
    FileWriter fw = new FileWriter(&amp;quot;file.dat&amp;quot;);&lt;br /&gt;
    String strs[] = { &amp;quot;com&amp;quot;, &amp;quot;exe&amp;quot;, &amp;quot;doc&amp;quot; };&lt;br /&gt;
    for (int i = 0; i &amp;lt; strs.length; i++) {&lt;br /&gt;
      fw.write(strs[i] + &amp;quot;\n&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    fw.close();&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;
== Using a Reader and a Writer, returns a String from an InputStream ==&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;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.io.InputStreamReader;&lt;br /&gt;
import java.io.StringWriter;&lt;br /&gt;
/* Copyright (c) 1995-2000, The Hypersonic SQL 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 Hypersonic SQL 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 THE HYPERSONIC SQL GROUP,&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;
 * This software consists of voluntary contributions made by many individuals&lt;br /&gt;
 * on behalf of the Hypersonic SQL Group.&lt;br /&gt;
 *&lt;br /&gt;
 *&lt;br /&gt;
 * For work added by the HSQL Development Group:&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;
 * Collection of static methods for converting strings between different formats&lt;br /&gt;
 * and to and from byte arrays.&lt;br /&gt;
 * &amp;lt;p&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * Includes some methods based on Hypersonic code as indicated.&lt;br /&gt;
 * &lt;br /&gt;
 * @author Thomas Mueller (Hypersonic SQL Group)&lt;br /&gt;
 * @author Fred Toussi (fredt@users dot sourceforge.net)&lt;br /&gt;
 * @version 1.9.0&lt;br /&gt;
 * @since 1.7.2&lt;br /&gt;
 */&lt;br /&gt;
public class Main {&lt;br /&gt;
  private static final byte[] HEXBYTES = { (byte) &amp;quot;0&amp;quot;, (byte) &amp;quot;1&amp;quot;, (byte) &amp;quot;2&amp;quot;, (byte) &amp;quot;3&amp;quot;,&lt;br /&gt;
      (byte) &amp;quot;4&amp;quot;, (byte) &amp;quot;5&amp;quot;, (byte) &amp;quot;6&amp;quot;, (byte) &amp;quot;7&amp;quot;, (byte) &amp;quot;8&amp;quot;, (byte) &amp;quot;9&amp;quot;, (byte) &amp;quot;a&amp;quot;,&lt;br /&gt;
      (byte) &amp;quot;b&amp;quot;, (byte) &amp;quot;c&amp;quot;, (byte) &amp;quot;d&amp;quot;, (byte) &amp;quot;e&amp;quot;, (byte) &amp;quot;f&amp;quot; };&lt;br /&gt;
&lt;br /&gt;
  /**&lt;br /&gt;
   * Using a Reader and a Writer, returns a String from an InputStream.&lt;br /&gt;
   *&lt;br /&gt;
   * Method based on Hypersonic Code&lt;br /&gt;
   *&lt;br /&gt;
   * @param x InputStream to read from&lt;br /&gt;
   * @throws IOException&lt;br /&gt;
   * @return a Java string&lt;br /&gt;
   */&lt;br /&gt;
  public static String inputStreamToString(InputStream x,&lt;br /&gt;
          String encoding) throws IOException {&lt;br /&gt;
      InputStreamReader in        = new InputStreamReader(x, encoding);&lt;br /&gt;
      StringWriter      writer    = new StringWriter();&lt;br /&gt;
      int               blocksize = 8 * 1024;&lt;br /&gt;
      char[]            buffer    = new char[blocksize];&lt;br /&gt;
      for (;;) {&lt;br /&gt;
          int read = in.read(buffer);&lt;br /&gt;
          if (read == -1) {&lt;br /&gt;
              break;&lt;br /&gt;
          }&lt;br /&gt;
          writer.write(buffer, 0, read);&lt;br /&gt;
      }&lt;br /&gt;
      writer.close();&lt;br /&gt;
      return writer.toString();&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>