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

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/File_Input_Output/StringWriter&amp;diff=6145&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/StringWriter&amp;diff=6145&amp;oldid=prev"/>
				<updated>2010-06-01T06:02:47Z</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:02, 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/StringWriter&amp;diff=6144&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/StringWriter&amp;diff=6144&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 string writer that is able to write large amounts of data. ==&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;
 * JFreeReport : a free Java reporting library&lt;br /&gt;
 * &lt;br /&gt;
 *&lt;br /&gt;
 * Project Info:  http://reporting.pentaho.org/&lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.&lt;br /&gt;
 *&lt;br /&gt;
 * This library is free software; you can redistribute it and/or modify it under the terms&lt;br /&gt;
 * of the GNU Lesser General Public License as published by the Free Software Foundation;&lt;br /&gt;
 * either version 2.1 of the License, or (at your option) any later version.&lt;br /&gt;
 *&lt;br /&gt;
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;&lt;br /&gt;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&lt;br /&gt;
 * See the GNU 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 License along with this&lt;br /&gt;
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,&lt;br /&gt;
 * Boston, MA 02111-1307, USA.&lt;br /&gt;
 *&lt;br /&gt;
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.&lt;br /&gt;
 * in the United States and other countries.]&lt;br /&gt;
 *&lt;br /&gt;
 * ------------&lt;br /&gt;
 * MemoryStringWriter.java&lt;br /&gt;
 * ------------&lt;br /&gt;
 * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.Writer;&lt;br /&gt;
/**&lt;br /&gt;
 * A string writer that is able to write large amounts of data. The original&lt;br /&gt;
 * StringWriter contained in Java doubles its buffersize everytime the buffer&lt;br /&gt;
 * overflows. This is nice with small amounts of data, but awfull for huge&lt;br /&gt;
 * buffers.&lt;br /&gt;
 * &lt;br /&gt;
 * @author Thomas Morgner&lt;br /&gt;
 */&lt;br /&gt;
public class MemoryStringWriter extends Writer {&lt;br /&gt;
  private int bufferIncrement;&lt;br /&gt;
  private int cursor;&lt;br /&gt;
  private char[] buffer;&lt;br /&gt;
  private int maximumBufferIncrement;&lt;br /&gt;
  /**&lt;br /&gt;
   * Create a new character-stream writer whose critical sections will&lt;br /&gt;
   * synchronize on the writer itself.&lt;br /&gt;
   */&lt;br /&gt;
  public MemoryStringWriter() {&lt;br /&gt;
    this(4096);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Create a new character-stream writer whose critical sections will&lt;br /&gt;
   * synchronize on the writer itself.&lt;br /&gt;
   */&lt;br /&gt;
  public MemoryStringWriter(final int bufferSize) {&lt;br /&gt;
    this(bufferSize, bufferSize * 4);&lt;br /&gt;
  }&lt;br /&gt;
  public MemoryStringWriter(final int bufferSize, final int maximumBufferIncrement) {&lt;br /&gt;
    this.maximumBufferIncrement = maximumBufferIncrement;&lt;br /&gt;
    this.bufferIncrement = bufferSize;&lt;br /&gt;
    this.buffer = new char[bufferSize];&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Write a portion of an array of characters.&lt;br /&gt;
   * &lt;br /&gt;
   * @param cbuf&lt;br /&gt;
   *          Array of characters&lt;br /&gt;
   * @param off&lt;br /&gt;
   *          Offset from which to start writing characters&lt;br /&gt;
   * @param len&lt;br /&gt;
   *          Number of characters to write&lt;br /&gt;
   * @throws java.io.IOException&lt;br /&gt;
   *           If an I/O error occurs&lt;br /&gt;
   */&lt;br /&gt;
  public synchronized void write(final char[] cbuf, final int off, final int len)&lt;br /&gt;
      throws IOException {&lt;br /&gt;
    if (len &amp;lt; 0) {&lt;br /&gt;
      throw new IllegalArgumentException();&lt;br /&gt;
    }&lt;br /&gt;
    if (off &amp;lt; 0) {&lt;br /&gt;
      throw new IndexOutOfBoundsException();&lt;br /&gt;
    }&lt;br /&gt;
    if (cbuf == null) {&lt;br /&gt;
      throw new NullPointerException();&lt;br /&gt;
    }&lt;br /&gt;
    if ((len + off) &amp;gt; cbuf.length) {&lt;br /&gt;
      throw new IndexOutOfBoundsException();&lt;br /&gt;
    }&lt;br /&gt;
    ensureSize(cursor + len);&lt;br /&gt;
    System.arraycopy(cbuf, off, this.buffer, cursor, len);&lt;br /&gt;
    cursor += len;&lt;br /&gt;
  }&lt;br /&gt;
  private void ensureSize(final int size) {&lt;br /&gt;
    if (this.buffer.length &amp;gt;= size) {&lt;br /&gt;
      return;&lt;br /&gt;
    }&lt;br /&gt;
    final int computedSize = (int) Math.min((this.buffer.length + 1) * 1.5, this.buffer.length&lt;br /&gt;
        + maximumBufferIncrement);&lt;br /&gt;
    final int newSize = Math.max(size, computedSize);&lt;br /&gt;
    final char[] newBuffer = new char[newSize];&lt;br /&gt;
    System.arraycopy(this.buffer, 0, newBuffer, 0, cursor);&lt;br /&gt;
    this.buffer = newBuffer;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Flush the stream. If the stream has saved any characters from the various&lt;br /&gt;
   * write() methods in a buffer, write them immediately to their intended&lt;br /&gt;
   * destination. Then, if that destination is another character or byte stream,&lt;br /&gt;
   * flush it. Thus one flush() invocation will flush all the buffers in a chain&lt;br /&gt;
   * of Writers and OutputStreams. &amp;lt;p/&amp;gt; If the intended destination of this&lt;br /&gt;
   * stream is an abstraction provided by the underlying operating system, for&lt;br /&gt;
   * example a file, then flushing the stream guarantees only that bytes&lt;br /&gt;
   * previously written to the stream are passed to the operating system for&lt;br /&gt;
   * writing; it does not guarantee that they are actually written to a physical&lt;br /&gt;
   * device such as a disk drive.&lt;br /&gt;
   * &lt;br /&gt;
   * @throws java.io.IOException&lt;br /&gt;
   *           If an I/O error occurs&lt;br /&gt;
   */&lt;br /&gt;
  public void flush() throws IOException {&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Close the stream, flushing it first. Once a stream has been closed, further&lt;br /&gt;
   * write() or flush() invocations will cause an IOException to be thrown.&lt;br /&gt;
   * Closing a previously-closed stream, however, has no effect.&lt;br /&gt;
   * &lt;br /&gt;
   * @throws java.io.IOException&lt;br /&gt;
   *           If an I/O error occurs&lt;br /&gt;
   */&lt;br /&gt;
  public void close() throws IOException {&lt;br /&gt;
  }&lt;br /&gt;
  public int getCursor() {&lt;br /&gt;
    return cursor;&lt;br /&gt;
  }&lt;br /&gt;
  public String toString() {&lt;br /&gt;
    return new String(buffer, 0, cursor);&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 IO ==&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.IOException;&lt;br /&gt;
import java.io.StringReader;&lt;br /&gt;
import java.io.StringWriter;&lt;br /&gt;
public class StringIOApp {&lt;br /&gt;
  public static void main(String args[]) throws IOException {&lt;br /&gt;
    StringWriter outStream = new StringWriter();&lt;br /&gt;
    String s = &amp;quot;This is a test.&amp;quot;;&lt;br /&gt;
    for (int i = 0; i &amp;lt; s.length(); ++i)&lt;br /&gt;
      outStream.write(s.charAt(i));&lt;br /&gt;
    System.out.println(&amp;quot;outstream: &amp;quot; + outStream);&lt;br /&gt;
    System.out.println(&amp;quot;size: &amp;quot; + outStream.toString().length());&lt;br /&gt;
    StringReader inStream;&lt;br /&gt;
    inStream = new StringReader(outStream.toString());&lt;br /&gt;
    int ch = 0;&lt;br /&gt;
    StringBuffer sb = new StringBuffer(&amp;quot;&amp;quot;);&lt;br /&gt;
    while ((ch = inStream.read()) != -1)&lt;br /&gt;
      sb.append((char) ch);&lt;br /&gt;
    s = sb.toString();&lt;br /&gt;
    System.out.println(s.length() + &amp;quot; characters were read&amp;quot;);&lt;br /&gt;
    System.out.println(&amp;quot;They are: &amp;quot; + s);&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>