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

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/File_Input_Output/OutputStream&amp;diff=6233&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/OutputStream&amp;diff=6233&amp;oldid=prev"/>
				<updated>2010-06-01T06:04:43Z</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/OutputStream&amp;diff=6232&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/OutputStream&amp;diff=6232&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 null output stream. All data written to this stream is ignored. ==&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;
 * NullOutputStream.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.OutputStream;&lt;br /&gt;
/**&lt;br /&gt;
 * A null output stream. All data written to this stream is ignored.&lt;br /&gt;
 *&lt;br /&gt;
 * @author Thomas Morgner&lt;br /&gt;
 */&lt;br /&gt;
public class NullOutputStream extends OutputStream&lt;br /&gt;
{&lt;br /&gt;
  /**&lt;br /&gt;
   * Default constructor.&lt;br /&gt;
   */&lt;br /&gt;
  public NullOutputStream ()&lt;br /&gt;
  {&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Writes to the stream (in this case, does nothing).&lt;br /&gt;
   *&lt;br /&gt;
   * @param i the value.&lt;br /&gt;
   * @throws IOException if there is an I/O problem.&lt;br /&gt;
   */&lt;br /&gt;
  public void write (final int i)&lt;br /&gt;
          throws IOException&lt;br /&gt;
  {&lt;br /&gt;
    // no i wont do anything here ...&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Writes to the stream (in this case, does nothing).&lt;br /&gt;
   *&lt;br /&gt;
   * @param bytes the bytes.&lt;br /&gt;
   * @throws IOException if there is an I/O problem.&lt;br /&gt;
   */&lt;br /&gt;
  public void write (final byte[] bytes)&lt;br /&gt;
          throws IOException&lt;br /&gt;
  {&lt;br /&gt;
    // no i wont do anything here ...&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Writes to the stream (in this case, does nothing).&lt;br /&gt;
   *&lt;br /&gt;
   * @param bytes the bytes.&lt;br /&gt;
   * @param off   the start offset in the data.&lt;br /&gt;
   * @param len   the number of bytes to write.&lt;br /&gt;
   * @throws IOException if there is an I/O problem.&lt;br /&gt;
   */&lt;br /&gt;
  public void write (final byte[] bytes, final int off, final int len)&lt;br /&gt;
          throws IOException&lt;br /&gt;
  {&lt;br /&gt;
    // no i wont do anything here ...&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;
== Byte Counting OutputStream ==&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;
import java.io.IOException;&lt;br /&gt;
import java.io.OutputStream;&lt;br /&gt;
/**&lt;br /&gt;
 * Output stream that counts bytes written to it (but discards them).&lt;br /&gt;
 * &lt;br /&gt;
 * @author Jonathan Locke&lt;br /&gt;
 */&lt;br /&gt;
public final class ByteCountingOutputStream extends OutputStream&lt;br /&gt;
{&lt;br /&gt;
  private long size;&lt;br /&gt;
  /**&lt;br /&gt;
   * @see java.io.OutputStream#write(int)&lt;br /&gt;
   */&lt;br /&gt;
  public void write(int b) throws IOException&lt;br /&gt;
  {&lt;br /&gt;
    size++;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * @see java.io.OutputStream#write(byte[], int, int)&lt;br /&gt;
   */&lt;br /&gt;
  public void write(byte b[], int off, int len) throws IOException&lt;br /&gt;
  {&lt;br /&gt;
    size += len;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * @return Number of bytes written to this stream&lt;br /&gt;
   */&lt;br /&gt;
  public long size()&lt;br /&gt;
  {&lt;br /&gt;
    return size;&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;
== Compare the contents of two Streams to determine if they are equal or not. ==&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;
 * Licensed to the Apache Software Foundation (ASF) under one or more&lt;br /&gt;
 * contributor license agreements.  See the NOTICE file distributed with&lt;br /&gt;
 * this work for additional information regarding copyright ownership.&lt;br /&gt;
 * The ASF licenses this file to You under the Apache License, Version 2.0&lt;br /&gt;
 * (the &amp;quot;License&amp;quot;); you may not use this file except in compliance with&lt;br /&gt;
 * 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, 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.BufferedInputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
/** * Origin of code: Apache Avalon (Excalibur)&lt;br /&gt;
 * &lt;br /&gt;
 * @author Peter Donald&lt;br /&gt;
 * @author Jeff Turner&lt;br /&gt;
 * @author Matthew Hawthorne&lt;br /&gt;
 * @author Stephen Colebourne&lt;br /&gt;
 * @author Gareth Davis&lt;br /&gt;
 * @version CVS $Revision$ $Date$*/&lt;br /&gt;
public class Main {&lt;br /&gt;
  /**&lt;br /&gt;
   * Compare the contents of two Streams to determine if they are equal or not.&lt;br /&gt;
   * &amp;lt;p&amp;gt;&lt;br /&gt;
   * This method buffers the input internally using &amp;lt;code&amp;gt;BufferedInputStream&amp;lt;/code&amp;gt; if they are&lt;br /&gt;
   * not already buffered.&lt;br /&gt;
   * &lt;br /&gt;
   * @param input1&lt;br /&gt;
   *            the first stream&lt;br /&gt;
   * @param input2&lt;br /&gt;
   *            the second stream&lt;br /&gt;
   * @return true if the content of the streams are equal or they both don&amp;quot;t exist, false&lt;br /&gt;
   *         otherwise&lt;br /&gt;
   * @throws NullPointerException&lt;br /&gt;
   *             if either input is null&lt;br /&gt;
   * @throws IOException&lt;br /&gt;
   *             if an I/O error occurs&lt;br /&gt;
   */&lt;br /&gt;
  public static boolean contentEquals(InputStream input1, InputStream input2) throws IOException&lt;br /&gt;
  {&lt;br /&gt;
    if (!(input1 instanceof BufferedInputStream))&lt;br /&gt;
    {&lt;br /&gt;
      input1 = new BufferedInputStream(input1);&lt;br /&gt;
    }&lt;br /&gt;
    if (!(input2 instanceof BufferedInputStream))&lt;br /&gt;
    {&lt;br /&gt;
      input2 = new BufferedInputStream(input2);&lt;br /&gt;
    }&lt;br /&gt;
    int ch = input1.read();&lt;br /&gt;
    while (-1 != ch)&lt;br /&gt;
    {&lt;br /&gt;
      int ch2 = input2.read();&lt;br /&gt;
      if (ch != ch2)&lt;br /&gt;
      {&lt;br /&gt;
        return false;&lt;br /&gt;
      }&lt;br /&gt;
      ch = input1.read();&lt;br /&gt;
    }&lt;br /&gt;
    int ch2 = input2.read();&lt;br /&gt;
    return (ch2 == -1);&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;
== Memory Byte Array OutputStream ==&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;
 * MemoryByteArrayOutputStream.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.OutputStream;&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 MemoryByteArrayOutputStream extends OutputStream {&lt;br /&gt;
  private int maximumBufferIncrement;&lt;br /&gt;
  private int cursor;&lt;br /&gt;
  private byte[] buffer;&lt;br /&gt;
  private byte[] singleIntArray;&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 MemoryByteArrayOutputStream() {&lt;br /&gt;
    this(4096, 65536);&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 MemoryByteArrayOutputStream(final int bufferSize, final int maximumBufferIncrement) {&lt;br /&gt;
    this.maximumBufferIncrement = maximumBufferIncrement;&lt;br /&gt;
    this.buffer = new byte[bufferSize];&lt;br /&gt;
    this.singleIntArray = new byte[1];&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 byte[] 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;
  /**&lt;br /&gt;
   * Writes &amp;lt;code&amp;gt;b.length&amp;lt;/code&amp;gt; bytes from the specified byte array to this&lt;br /&gt;
   * output stream. The general contract for &amp;lt;code&amp;gt;write(b)&amp;lt;/code&amp;gt; is that it&lt;br /&gt;
   * should have exactly the same effect as the call &amp;lt;code&amp;gt;write(b, 0,&lt;br /&gt;
   * b.length)&amp;lt;/code&amp;gt;.&lt;br /&gt;
   * &lt;br /&gt;
   * @param b&lt;br /&gt;
   *          the data.&lt;br /&gt;
   * @throws java.io.IOException&lt;br /&gt;
   *           if an I/O error occurs.&lt;br /&gt;
   * @see java.io.OutputStream#write(byte[], int, int)&lt;br /&gt;
   */&lt;br /&gt;
  public void write(final byte[] b) throws IOException {&lt;br /&gt;
    write(b, 0, b.length);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Writes the specified byte to this output stream. The general contract for&lt;br /&gt;
   * &amp;lt;code&amp;gt;write&amp;lt;/code&amp;gt; is that one byte is written to the output stream. The&lt;br /&gt;
   * byte to be written is the eight low-order bits of the argument&lt;br /&gt;
   * &amp;lt;code&amp;gt;b&amp;lt;/code&amp;gt;. The 24 high-order bits of &amp;lt;code&amp;gt;b&amp;lt;/code&amp;gt; are ignored.&lt;br /&gt;
   * &amp;lt;p/&amp;gt; Subclasses of &amp;lt;code&amp;gt;OutputStream&amp;lt;/code&amp;gt; must provide an&lt;br /&gt;
   * implementation for this method.&lt;br /&gt;
   * &lt;br /&gt;
   * @param b&lt;br /&gt;
   *          the &amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;.&lt;br /&gt;
   * @throws java.io.IOException&lt;br /&gt;
   *           if an I/O error occurs. In particular, an&lt;br /&gt;
   *           &amp;lt;code&amp;gt;IOException&amp;lt;/code&amp;gt; may be thrown if the output stream has&lt;br /&gt;
   *           been closed.&lt;br /&gt;
   */&lt;br /&gt;
  public synchronized void write(final int b) throws IOException {&lt;br /&gt;
    this.singleIntArray[0] = (byte) (0xFF &amp;amp; b);&lt;br /&gt;
    write(singleIntArray, 0, 1);&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 byte[] newBuffer = new byte[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;
    if ((buffer.length - cursor) &amp;gt; 50000) {&lt;br /&gt;
      System.out.println(&amp;quot;WASTED: &amp;quot; + (buffer.length - cursor));&lt;br /&gt;
    }&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 synchronized byte[] toByteArray() {&lt;br /&gt;
    final byte[] retval = new byte[cursor];&lt;br /&gt;
    System.arraycopy(buffer, 0, retval, 0, cursor);&lt;br /&gt;
    return retval;&lt;br /&gt;
  }&lt;br /&gt;
  public int getLength() {&lt;br /&gt;
    return cursor;&lt;br /&gt;
  }&lt;br /&gt;
  public byte[] getRaw() {&lt;br /&gt;
    if ((buffer.length - cursor) &amp;gt; 50000) {&lt;br /&gt;
      System.out.println(&amp;quot;WASTED: &amp;quot; + (buffer.length - cursor) + &amp;quot; Length: &amp;quot; + buffer.length);&lt;br /&gt;
    }&lt;br /&gt;
    return buffer;&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;
== Read from InputStream and write to OutputStream ==&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.OutputStream;&lt;br /&gt;
public class Main {&lt;br /&gt;
  /**&lt;br /&gt;
   * Read input from input stream and write it to output stream &lt;br /&gt;
   * until there is no more input from input stream.&lt;br /&gt;
   *&lt;br /&gt;
   * @param is input stream the input stream to read from.&lt;br /&gt;
   * @param os output stream the output stream to write to.&lt;br /&gt;
   * @param buf the byte array to use as a buffer&lt;br /&gt;
   */&lt;br /&gt;
  public static void flow( InputStream is, OutputStream os, byte[] buf ) &lt;br /&gt;
      throws IOException {&lt;br /&gt;
      int numRead;&lt;br /&gt;
      while ( (numRead = is.read(buf) ) &amp;gt;= 0) {&lt;br /&gt;
          os.write(buf, 0, numRead);&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;
== String Buffer OutputStream ==&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;
 * Created on Dec 25, 2004&lt;br /&gt;
 * &lt;br /&gt;
 * Copyright 2005 CafeSip.org &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;
 *&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, 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;
 */&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.OutputStream;&lt;br /&gt;
/**&lt;br /&gt;
 * @author amit&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
public class StringBufferOutputStream extends OutputStream&lt;br /&gt;
{&lt;br /&gt;
    private StringBuffer textBuffer = new StringBuffer();&lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * &lt;br /&gt;
     */&lt;br /&gt;
    public StringBufferOutputStream()&lt;br /&gt;
    {&lt;br /&gt;
        super();&lt;br /&gt;
    }&lt;br /&gt;
    /*&lt;br /&gt;
     * @see java.io.OutputStream#write(int)&lt;br /&gt;
     */&lt;br /&gt;
    public void write(int b) throws IOException&lt;br /&gt;
    {&lt;br /&gt;
        char a = (char)b;&lt;br /&gt;
        textBuffer.append(a);&lt;br /&gt;
    }&lt;br /&gt;
    public String toString()&lt;br /&gt;
    {&lt;br /&gt;
        return textBuffer.toString();&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
    public void clear()&lt;br /&gt;
    {&lt;br /&gt;
        textBuffer.delete(0, textBuffer.length());&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;/div&gt;</summary>
			</entry>

	</feed>