<?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_Tutorial%2FFile%2FFilterInputStream</id>
		<title>Java Tutorial/File/FilterInputStream - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FFile%2FFilterInputStream"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/File/FilterInputStream&amp;action=history"/>
		<updated>2026-04-22T08:17:42Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/File/FilterInputStream&amp;diff=5328&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/File/FilterInputStream&amp;diff=5328&amp;oldid=prev"/>
				<updated>2010-06-01T05:19:31Z</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;Версия 05:19, 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_Tutorial/File/FilterInputStream&amp;diff=5327&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/File/FilterInputStream&amp;diff=5327&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:27Z</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;==  An limited-data-size input stream ==&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;
 * 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.FilterInputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * An input stream, which limits its data size. This stream is&lt;br /&gt;
 * used, if the content length is unknown.&lt;br /&gt;
 */&lt;br /&gt;
public abstract class LimitedInputStream&lt;br /&gt;
        extends FilterInputStream {&lt;br /&gt;
    /**&lt;br /&gt;
     * The maximum size of an item, in bytes.&lt;br /&gt;
     */&lt;br /&gt;
    private long sizeMax;&lt;br /&gt;
    /**&lt;br /&gt;
     * The current number of bytes.&lt;br /&gt;
     */&lt;br /&gt;
    private long count;&lt;br /&gt;
    /**&lt;br /&gt;
     * Whether this stream is already closed.&lt;br /&gt;
     */&lt;br /&gt;
    private boolean closed;&lt;br /&gt;
    /**&lt;br /&gt;
     * Creates a new instance.&lt;br /&gt;
     * @param pIn The input stream, which shall be limited.&lt;br /&gt;
     * @param pSizeMax The limit; no more than this number of bytes&lt;br /&gt;
     *   shall be returned by the source stream.&lt;br /&gt;
     */&lt;br /&gt;
    public LimitedInputStream(InputStream pIn, long pSizeMax) {&lt;br /&gt;
        super(pIn);&lt;br /&gt;
        sizeMax = pSizeMax;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Called to indicate, that the input streams limit has&lt;br /&gt;
     * been exceeded.&lt;br /&gt;
     * @param pSizeMax The input streams limit, in bytes.&lt;br /&gt;
     * @param pCount The actual number of bytes.&lt;br /&gt;
     * @throws IOException The called method is expected&lt;br /&gt;
     *   to raise an IOException.&lt;br /&gt;
     */&lt;br /&gt;
    protected abstract void raiseError(long pSizeMax, long pCount)&lt;br /&gt;
            throws IOException;&lt;br /&gt;
    /** Called to check, whether the input streams&lt;br /&gt;
     * limit is reached.&lt;br /&gt;
     * @throws IOException The given limit is exceeded.&lt;br /&gt;
     */&lt;br /&gt;
    private void checkLimit() throws IOException {&lt;br /&gt;
        if (count &amp;gt; sizeMax) {&lt;br /&gt;
            raiseError(sizeMax, count);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Reads the next byte of data from this input stream. The value&lt;br /&gt;
     * byte is returned as an &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; in the range&lt;br /&gt;
     * &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;255&amp;lt;/code&amp;gt;. If no byte is available&lt;br /&gt;
     * because the end of the stream has been reached, the value&lt;br /&gt;
     * &amp;lt;code&amp;gt;-1&amp;lt;/code&amp;gt; is returned. This method blocks until input data&lt;br /&gt;
     * is available, the end of the stream is detected, or an exception&lt;br /&gt;
     * is thrown.&lt;br /&gt;
     * &lt;br /&gt;
     * This method&lt;br /&gt;
     * simply performs &amp;lt;code&amp;gt;in.read()&amp;lt;/code&amp;gt; and returns the result.&lt;br /&gt;
     *&lt;br /&gt;
     * @return     the next byte of data, or &amp;lt;code&amp;gt;-1&amp;lt;/code&amp;gt; if the end of the&lt;br /&gt;
     *             stream is reached.&lt;br /&gt;
     * @exception  IOException  if an I/O error occurs.&lt;br /&gt;
     * @see        java.io.FilterInputStream#in&lt;br /&gt;
     */&lt;br /&gt;
    public int read() throws IOException {&lt;br /&gt;
        int res = super.read();&lt;br /&gt;
        if (res != -1) {&lt;br /&gt;
            count++;&lt;br /&gt;
            checkLimit();&lt;br /&gt;
        }&lt;br /&gt;
        return res;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Reads up to &amp;lt;code&amp;gt;len&amp;lt;/code&amp;gt; bytes of data from this input stream&lt;br /&gt;
     * into an array of bytes. If &amp;lt;code&amp;gt;len&amp;lt;/code&amp;gt; is not zero, the method&lt;br /&gt;
     * blocks until some input is available; otherwise, no&lt;br /&gt;
     * bytes are read and &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; is returned.&lt;br /&gt;
     * &lt;br /&gt;
     * This method simply performs &amp;lt;code&amp;gt;in.read(b, off, len)&amp;lt;/code&amp;gt;&lt;br /&gt;
     * and returns the result.&lt;br /&gt;
     *&lt;br /&gt;
     * @param      b     the buffer into which the data is read.&lt;br /&gt;
     * @param      off   The start offset in the destination array&lt;br /&gt;
     *                   &amp;lt;code&amp;gt;b&amp;lt;/code&amp;gt;.&lt;br /&gt;
     * @param      len   the maximum number of bytes read.&lt;br /&gt;
     * @return     the total number of bytes read into the buffer, or&lt;br /&gt;
     *             &amp;lt;code&amp;gt;-1&amp;lt;/code&amp;gt; if there is no more data because the end of&lt;br /&gt;
     *             the stream has been reached.&lt;br /&gt;
     * @exception  NullPointerException If &amp;lt;code&amp;gt;b&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt;.&lt;br /&gt;
     * @exception  IndexOutOfBoundsException If &amp;lt;code&amp;gt;off&amp;lt;/code&amp;gt; is negative,&lt;br /&gt;
     * &amp;lt;code&amp;gt;len&amp;lt;/code&amp;gt; is negative, or &amp;lt;code&amp;gt;len&amp;lt;/code&amp;gt; is greater than&lt;br /&gt;
     * &amp;lt;code&amp;gt;b.length - off&amp;lt;/code&amp;gt;&lt;br /&gt;
     * @exception  IOException  if an I/O error occurs.&lt;br /&gt;
     * @see        java.io.FilterInputStream#in&lt;br /&gt;
     */&lt;br /&gt;
    public int read(byte[] b, int off, int len) throws IOException {&lt;br /&gt;
        int res = super.read(b, off, len);&lt;br /&gt;
        if (res &amp;gt; 0) {&lt;br /&gt;
            count += res;&lt;br /&gt;
            checkLimit();&lt;br /&gt;
        }&lt;br /&gt;
        return res;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Returns, whether this stream is already closed.&lt;br /&gt;
     * @return True, if the stream is closed, otherwise false.&lt;br /&gt;
     * @throws IOException An I/O error occurred.&lt;br /&gt;
     */&lt;br /&gt;
    public boolean isClosed() throws IOException {&lt;br /&gt;
        return closed;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Closes this input stream and releases any system resources&lt;br /&gt;
     * associated with the stream.&lt;br /&gt;
     * This&lt;br /&gt;
     * method simply performs &amp;lt;code&amp;gt;in.close()&amp;lt;/code&amp;gt;.&lt;br /&gt;
     *&lt;br /&gt;
     * @exception  IOException  if an I/O error occurs.&lt;br /&gt;
     * @see        java.io.FilterInputStream#in&lt;br /&gt;
     */&lt;br /&gt;
    public void close() throws IOException {&lt;br /&gt;
        closed = true;&lt;br /&gt;
        super.close();&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;
==  A trace of the data that is being retrieved from an input stream ==&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;
 * The contents of this file are subject to the terms &lt;br /&gt;
 * of the Common Development and Distribution License &lt;br /&gt;
 * (the &amp;quot;License&amp;quot;).  You may not use this file except &lt;br /&gt;
 * in compliance with the License.&lt;br /&gt;
 * &lt;br /&gt;
 * You can obtain a copy of the license at &lt;br /&gt;
 * glassfish/bootstrap/legal/CDDLv1.0.txt or &lt;br /&gt;
 * https://glassfish.dev.java.net/public/CDDLv1.0.html. &lt;br /&gt;
 * See the License for the specific language governing &lt;br /&gt;
 * permissions and limitations under the License.&lt;br /&gt;
 * &lt;br /&gt;
 * When distributing Covered Code, include this CDDL &lt;br /&gt;
 * HEADER in each file and include the License file at &lt;br /&gt;
 * glassfish/bootstrap/legal/CDDLv1.0.txt.  If applicable, &lt;br /&gt;
 * add the following below this CDDL HEADER, with the &lt;br /&gt;
 * fields enclosed by brackets &amp;quot;[]&amp;quot; replaced with your &lt;br /&gt;
 * own identifying information: Portions Copyright [yyyy] &lt;br /&gt;
 * [name of copyright owner]&lt;br /&gt;
 */&lt;br /&gt;
/*&lt;br /&gt;
 * @(#)TraceInputStream.java  1.7 05/08/29&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.&lt;br /&gt;
 */&lt;br /&gt;
//Revised from sun mail util&lt;br /&gt;
import java.io.*;&lt;br /&gt;
/**&lt;br /&gt;
 * This class is a FilterInputStream that writes the bytes&lt;br /&gt;
 * being read from the given input stream into the given output&lt;br /&gt;
 * stream. This class is typically used to provide a trace of&lt;br /&gt;
 * the data that is being retrieved from an input stream.&lt;br /&gt;
 *&lt;br /&gt;
 * @author John Mani&lt;br /&gt;
 */&lt;br /&gt;
public class TraceInputStream extends FilterInputStream {&lt;br /&gt;
    private boolean trace = false;&lt;br /&gt;
    private boolean quote = false;&lt;br /&gt;
    private OutputStream traceOut;&lt;br /&gt;
    /**&lt;br /&gt;
     * Creates an input stream filter built on top of the specified&lt;br /&gt;
     * input stream.&lt;br /&gt;
     *   &lt;br /&gt;
     * @param   in   the underlying input stream.&lt;br /&gt;
     * @param   out  the trace stream&lt;br /&gt;
     */&lt;br /&gt;
    public TraceInputStream(InputStream in, OutputStream traceOut) {&lt;br /&gt;
  super(in);&lt;br /&gt;
  this.traceOut = traceOut;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Set trace mode.&lt;br /&gt;
     * @param trace the trace mode&lt;br /&gt;
     */&lt;br /&gt;
    public void setTrace(boolean trace) {&lt;br /&gt;
  this.trace = trace;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Set quote mode.&lt;br /&gt;
     * @param quote the quote mode&lt;br /&gt;
     */&lt;br /&gt;
    public void setQuote(boolean quote) {&lt;br /&gt;
  this.quote = quote;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Reads the next byte of data from this input stream. Returns&lt;br /&gt;
     * &amp;lt;code&amp;gt;-1&amp;lt;/code&amp;gt; if no data is available. Writes out the read&lt;br /&gt;
     * byte into the trace stream, if trace mode is &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;&lt;br /&gt;
     */&lt;br /&gt;
    public int read() throws IOException {&lt;br /&gt;
  int b = in.read();&lt;br /&gt;
  if (trace &amp;amp;&amp;amp; b != -1) {&lt;br /&gt;
      if (quote)&lt;br /&gt;
    writeByte(b);&lt;br /&gt;
      else&lt;br /&gt;
    traceOut.write(b);&lt;br /&gt;
  }&lt;br /&gt;
  return b;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Reads up to &amp;lt;code&amp;gt;len&amp;lt;/code&amp;gt; bytes of data from this input stream&lt;br /&gt;
     * into an array of bytes. Returns &amp;lt;code&amp;gt;-1&amp;lt;/code&amp;gt; if no more data&lt;br /&gt;
     * is available. Writes out the read bytes into the trace stream, if &lt;br /&gt;
     * trace mode is &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;&lt;br /&gt;
     */&lt;br /&gt;
    public int read(byte b[], int off, int len) throws IOException {&lt;br /&gt;
  int count = in.read(b, off, len);&lt;br /&gt;
  if (trace &amp;amp;&amp;amp; count != -1) {&lt;br /&gt;
      if (quote) {&lt;br /&gt;
    for (int i = 0; i &amp;lt; count; i++)&lt;br /&gt;
        writeByte(b[off + i]);&lt;br /&gt;
      } else&lt;br /&gt;
    traceOut.write(b, off, count);&lt;br /&gt;
  }&lt;br /&gt;
  return count;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Write a byte in a way that every byte value is printable ASCII.&lt;br /&gt;
     */&lt;br /&gt;
    private final void writeByte(int b) throws IOException {&lt;br /&gt;
  b &amp;amp;= 0xff;&lt;br /&gt;
  if (b &amp;gt; 0x7f) {&lt;br /&gt;
      traceOut.write(&amp;quot;M&amp;quot;);&lt;br /&gt;
      traceOut.write(&amp;quot;-&amp;quot;);&lt;br /&gt;
      b &amp;amp;= 0x7f;&lt;br /&gt;
  }&lt;br /&gt;
  if (b == &amp;quot;\r&amp;quot;) {&lt;br /&gt;
      traceOut.write(&amp;quot;\\&amp;quot;);&lt;br /&gt;
      traceOut.write(&amp;quot;r&amp;quot;);&lt;br /&gt;
  } else if (b == &amp;quot;\n&amp;quot;) {&lt;br /&gt;
      traceOut.write(&amp;quot;\\&amp;quot;);&lt;br /&gt;
      traceOut.write(&amp;quot;n&amp;quot;);&lt;br /&gt;
      traceOut.write(&amp;quot;\n&amp;quot;);&lt;br /&gt;
  } else if (b == &amp;quot;\t&amp;quot;) {&lt;br /&gt;
      traceOut.write(&amp;quot;\\&amp;quot;);&lt;br /&gt;
      traceOut.write(&amp;quot;t&amp;quot;);&lt;br /&gt;
  } else if (b &amp;lt; &amp;quot; &amp;quot;) {&lt;br /&gt;
      traceOut.write(&amp;quot;^&amp;quot;);&lt;br /&gt;
      traceOut.write(&amp;quot;@&amp;quot; + b);&lt;br /&gt;
  } else {&lt;br /&gt;
      traceOut.write(b);&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;
==  introduce a protocol for reading arbitrary length data in a uniform way ==&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;
 * 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;
&lt;br /&gt;
import java.io.DataInputStream;&lt;br /&gt;
import java.io.FilterInputStream;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
/**&lt;br /&gt;
 * This input stream works in conjunction with the WrappedOutputStream&lt;br /&gt;
 * to introduce a protocol for reading arbitrary length data in a&lt;br /&gt;
 * uniform way.&lt;br /&gt;
 * &lt;br /&gt;
 * &amp;lt;strong&amp;gt;Note:&amp;lt;/strong&amp;gt; See the javadoc for WrappedOutputStream for&lt;br /&gt;
 * more information.&lt;br /&gt;
 *&lt;br /&gt;
 * @see WrappedOutputStream&lt;br /&gt;
 *&lt;br /&gt;
 * @author Andy Clark, IBM&lt;br /&gt;
 *&lt;br /&gt;
 * @version $Id: WrappedInputStream.java 447688 2006-09-19 02:39:49Z mrglavas $&lt;br /&gt;
 */&lt;br /&gt;
public class WrappedInputStream&lt;br /&gt;
    extends FilterInputStream {&lt;br /&gt;
    //&lt;br /&gt;
    // Data&lt;br /&gt;
    //&lt;br /&gt;
    /** Bytes left on input stream for current packet. */&lt;br /&gt;
    protected int fPacketCount;&lt;br /&gt;
    /** &lt;br /&gt;
     * Data input stream. This stream is used to input the block sizes&lt;br /&gt;
     * from the data stream that are written by the WrappedOutputStream.&lt;br /&gt;
     * &lt;br /&gt;
     * &amp;lt;strong&amp;gt;Note:&amp;lt;/strong&amp;gt; The data input stream is only used for&lt;br /&gt;
     * reading the byte count for performance reasons. We avoid the&lt;br /&gt;
     * method indirection for reading the byte data.&lt;br /&gt;
     */&lt;br /&gt;
    protected DataInputStream fDataInputStream;&lt;br /&gt;
    /** To mark that the stream is &amp;quot;closed&amp;quot;. */&lt;br /&gt;
    protected boolean fClosed;&lt;br /&gt;
    //&lt;br /&gt;
    // Constructors&lt;br /&gt;
    //&lt;br /&gt;
    /** Constructs a wrapper for the given an input stream. */&lt;br /&gt;
    public WrappedInputStream(InputStream stream) {&lt;br /&gt;
        super(stream);&lt;br /&gt;
        fDataInputStream = new DataInputStream(stream);&lt;br /&gt;
    } // &amp;lt;init&amp;gt;(InputStream)&lt;br /&gt;
    //&lt;br /&gt;
    // InputStream methods&lt;br /&gt;
    //&lt;br /&gt;
    /** Reads a single byte. */&lt;br /&gt;
    public int read() throws IOException {&lt;br /&gt;
        // ignore, if already closed&lt;br /&gt;
        if (fClosed) {&lt;br /&gt;
            return -1;&lt;br /&gt;
        }&lt;br /&gt;
        // read packet header&lt;br /&gt;
        if (fPacketCount == 0) {&lt;br /&gt;
            fPacketCount = fDataInputStream.readInt() &amp;amp; 0x7FFFFFFF;&lt;br /&gt;
            if (fPacketCount == 0) {&lt;br /&gt;
                fClosed = true;&lt;br /&gt;
                return -1;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // read a byte from the packet&lt;br /&gt;
        fPacketCount--;&lt;br /&gt;
        return super.in.read();&lt;br /&gt;
    } // read():int&lt;br /&gt;
    /** &lt;br /&gt;
     * Reads a block of bytes and returns the total number of bytes read. &lt;br /&gt;
     */&lt;br /&gt;
    public int read(byte[] b, int offset, int length) throws IOException {&lt;br /&gt;
        // ignore, if already closed&lt;br /&gt;
        if (fClosed) {&lt;br /&gt;
            return -1;&lt;br /&gt;
        }&lt;br /&gt;
        // read packet header&lt;br /&gt;
        if (fPacketCount == 0) {&lt;br /&gt;
            fPacketCount = fDataInputStream.readInt() &amp;amp; 0x7FFFFFFF;&lt;br /&gt;
            if (fPacketCount == 0) {&lt;br /&gt;
                fClosed = true;&lt;br /&gt;
                return -1;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        // read bytes from packet&lt;br /&gt;
        if (length &amp;gt; fPacketCount) {&lt;br /&gt;
            length = fPacketCount;&lt;br /&gt;
        }&lt;br /&gt;
        int count = super.in.read(b, offset, length);&lt;br /&gt;
        if (count == -1) {&lt;br /&gt;
            // NOTE: This condition should not happen. The end of &lt;br /&gt;
            //       the stream should always be designated by a &lt;br /&gt;
            //       byte count header of 0. -Ac&lt;br /&gt;
            fClosed = true;&lt;br /&gt;
            return -1;&lt;br /&gt;
        }&lt;br /&gt;
        fPacketCount -= count;&lt;br /&gt;
        // return total bytes read&lt;br /&gt;
        return count;&lt;br /&gt;
    } // read(byte[],int,int):int&lt;br /&gt;
    /** Skips the specified number of bytes from the input stream. */&lt;br /&gt;
    public long skip(long n) throws IOException {&lt;br /&gt;
        if (!fClosed) {&lt;br /&gt;
            // NOTE: This should be rewritten to be more efficient. -Ac&lt;br /&gt;
            for (long i = 0; i &amp;lt; n; i++) {&lt;br /&gt;
                int b = read();&lt;br /&gt;
                if (b == -1) {&lt;br /&gt;
                    return i + 1;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            return n;&lt;br /&gt;
        }&lt;br /&gt;
        return 0;&lt;br /&gt;
    } // skip(long):long&lt;br /&gt;
    /** &lt;br /&gt;
     * Closes the input stream. This method will search for the end of&lt;br /&gt;
     * the wrapped input, positioning the stream at after the end packet.&lt;br /&gt;
     * &lt;br /&gt;
     * &amp;lt;strong&amp;gt;Note:&amp;lt;/strong&amp;gt; This method does not close the underlying&lt;br /&gt;
     * input stream.&lt;br /&gt;
     */&lt;br /&gt;
    public void close() throws IOException {&lt;br /&gt;
        if (!fClosed) {&lt;br /&gt;
            fClosed = true;&lt;br /&gt;
            do {&lt;br /&gt;
                super.in.skip(fPacketCount);&lt;br /&gt;
                fPacketCount = fDataInputStream.readInt() &amp;amp; 0x7FFFFFFF;&lt;br /&gt;
            } while (fPacketCount &amp;gt; 0);&lt;br /&gt;
        }&lt;br /&gt;
    } // close()&lt;br /&gt;
} // class WrappedInputStream&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;
&lt;br /&gt;
import java.io.DataOutputStream;&lt;br /&gt;
import java.io.FilterOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.OutputStream;&lt;br /&gt;
/**&lt;br /&gt;
 * This output stream works in conjunction with the WrappedInputStream&lt;br /&gt;
 * to introduce a protocol for sending arbitrary length data in a&lt;br /&gt;
 * uniform way. This output stream allows variable length data to be&lt;br /&gt;
 * inserted into an existing output stream so that it can be read by&lt;br /&gt;
 * an input stream without reading too many bytes (in case of buffering&lt;br /&gt;
 * by the input stream).&lt;br /&gt;
 * &lt;br /&gt;
 * This output stream is used like any normal output stream. The protocol&lt;br /&gt;
 * is introduced by the WrappedOutputStream and does not need to be known&lt;br /&gt;
 * by the user of this class. However, for those that are interested, the&lt;br /&gt;
 * method is described below.&lt;br /&gt;
 * &lt;br /&gt;
 * The output stream writes the requested bytes as packets of binary&lt;br /&gt;
 * information. The packet consists of a header and payload. The header&lt;br /&gt;
 * is two bytes of a single unsigned short (written in network order) &lt;br /&gt;
 * that specifies the length of bytes in the payload. A header value of&lt;br /&gt;
 * 0 indicates that the stream is &amp;quot;closed&amp;quot;.&lt;br /&gt;
 * &lt;br /&gt;
 * &amp;lt;strong&amp;gt;Note:&amp;lt;/strong&amp;gt; For this wrapped output stream to be used,&lt;br /&gt;
 * the application &amp;lt;strong&amp;gt;must&amp;lt;/strong&amp;gt; call &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&lt;br /&gt;
 * to end the output.&lt;br /&gt;
 *&lt;br /&gt;
 * @see WrappedInputStream&lt;br /&gt;
 *&lt;br /&gt;
 * @author Andy Clark, IBM&lt;br /&gt;
 *&lt;br /&gt;
 * @version $Id: WrappedOutputStream.java 447688 2006-09-19 02:39:49Z mrglavas $&lt;br /&gt;
 */&lt;br /&gt;
public class WrappedOutputStream&lt;br /&gt;
    extends FilterOutputStream {&lt;br /&gt;
    //&lt;br /&gt;
    // Constants&lt;br /&gt;
    //&lt;br /&gt;
    /** Default buffer size (1024). */&lt;br /&gt;
    public static final int DEFAULT_BUFFER_SIZE = 1024;&lt;br /&gt;
    //&lt;br /&gt;
    // Data&lt;br /&gt;
    //&lt;br /&gt;
    /** Buffer. */&lt;br /&gt;
    protected byte[] fBuffer;&lt;br /&gt;
    /** Buffer position. */&lt;br /&gt;
    protected int fPosition;&lt;br /&gt;
    /** &lt;br /&gt;
     * Data output stream. This stream is used to output the block sizes&lt;br /&gt;
     * into the data stream that are read by the WrappedInputStream.&lt;br /&gt;
     * &lt;br /&gt;
     * &amp;lt;strong&amp;gt;Note:&amp;lt;/strong&amp;gt; The data output stream is only used for&lt;br /&gt;
     * writing the byte count for performance reasons. We avoid the&lt;br /&gt;
     * method indirection for writing the byte data.&lt;br /&gt;
     */&lt;br /&gt;
    protected DataOutputStream fDataOutputStream;&lt;br /&gt;
    //&lt;br /&gt;
    // Constructors&lt;br /&gt;
    //&lt;br /&gt;
    /** Constructs a wrapper for the given output stream. */&lt;br /&gt;
    public WrappedOutputStream(OutputStream stream) {&lt;br /&gt;
        this(stream, DEFAULT_BUFFER_SIZE);&lt;br /&gt;
    } // &amp;lt;init&amp;gt;(OutputStream)&lt;br /&gt;
    /** &lt;br /&gt;
     * Constructs a wrapper for the given output stream with the&lt;br /&gt;
     * given buffer size.&lt;br /&gt;
     */&lt;br /&gt;
    public WrappedOutputStream(OutputStream stream, int bufferSize) {&lt;br /&gt;
        super(stream);&lt;br /&gt;
        fBuffer = new byte[bufferSize];&lt;br /&gt;
        fDataOutputStream = new DataOutputStream(stream);&lt;br /&gt;
    } // &amp;lt;init&amp;gt;(OutputStream)&lt;br /&gt;
    //&lt;br /&gt;
    // OutputStream methods&lt;br /&gt;
    //&lt;br /&gt;
    /** &lt;br /&gt;
     * Writes a single byte to the output. &lt;br /&gt;
     * &lt;br /&gt;
     * &amp;lt;strong&amp;gt;Note:&amp;lt;/strong&amp;gt; Single bytes written to the output stream&lt;br /&gt;
     * will be buffered&lt;br /&gt;
     */&lt;br /&gt;
    public void write(int b) throws IOException {&lt;br /&gt;
        fBuffer[fPosition++] = (byte)b;&lt;br /&gt;
        if (fPosition == fBuffer.length) {&lt;br /&gt;
            fPosition = 0;&lt;br /&gt;
            fDataOutputStream.writeInt(fBuffer.length);&lt;br /&gt;
            super.out.write(fBuffer, 0, fBuffer.length);&lt;br /&gt;
        }&lt;br /&gt;
    } // write(int)&lt;br /&gt;
    /** Writes an array of bytes to the output. */&lt;br /&gt;
    public void write(byte[] b, int offset, int length) &lt;br /&gt;
        throws IOException {&lt;br /&gt;
        // flush existing buffer&lt;br /&gt;
        if (fPosition &amp;gt; 0) {&lt;br /&gt;
            flush0();&lt;br /&gt;
        }&lt;br /&gt;
        // write header followed by actual bytes&lt;br /&gt;
        fDataOutputStream.writeInt(length);&lt;br /&gt;
        super.out.write(b, offset, length);&lt;br /&gt;
    } // write(byte[])&lt;br /&gt;
    /** &lt;br /&gt;
     * Flushes the output buffer, writing all bytes currently in&lt;br /&gt;
     * the buffer to the output.&lt;br /&gt;
     */&lt;br /&gt;
    public void flush() throws IOException {&lt;br /&gt;
        flush0();&lt;br /&gt;
        super.out.flush();&lt;br /&gt;
    } // flush()&lt;br /&gt;
    /** &lt;br /&gt;
     * Closes the output stream. This method &amp;lt;strong&amp;gt;must&amp;lt;/strong&amp;gt; be&lt;br /&gt;
     * called when done writing all data to the output stream.&lt;br /&gt;
     * &lt;br /&gt;
     * &amp;lt;strong&amp;gt;Note:&amp;lt;/strong&amp;gt; This method does &amp;lt;em&amp;gt;not&amp;lt;/em&amp;gt; close the&lt;br /&gt;
     * actual output stream, only makes the input stream see the stream&lt;br /&gt;
     * closed. Do not write bytes after closing the output stream.&lt;br /&gt;
     */&lt;br /&gt;
    public void close() throws IOException {&lt;br /&gt;
        flush0();&lt;br /&gt;
        fDataOutputStream.writeInt(0);&lt;br /&gt;
        super.out.flush();&lt;br /&gt;
    } // close()&lt;br /&gt;
    //&lt;br /&gt;
    // Protected methods&lt;br /&gt;
    //&lt;br /&gt;
    /** &lt;br /&gt;
     * Flushes the output buffer, writing all bytes currently in&lt;br /&gt;
     * the buffer to the output. This method does not call the&lt;br /&gt;
     * flush() method of the output stream; it merely writes the&lt;br /&gt;
     * remaining bytes in the buffer.&lt;br /&gt;
     */&lt;br /&gt;
    public void flush0() throws IOException {&lt;br /&gt;
        int length = fPosition;&lt;br /&gt;
        fPosition = 0;&lt;br /&gt;
        if (length &amp;gt; 0) {&lt;br /&gt;
            fDataOutputStream.writeInt(length);&lt;br /&gt;
            super.out.write(fBuffer, 0, length);&lt;br /&gt;
        }&lt;br /&gt;
    } // flush0()&lt;br /&gt;
} // class WrappedOutputStream&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 from an underlying InputStream up to a defined number of bytes or the end of the underlying stream ==&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;
 * 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;
/* $Id: SubInputStream.java 604883 2007-12-17 14:36:37Z jeremias $ */&lt;br /&gt;
&lt;br /&gt;
import java.io.FilterInputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
/**&lt;br /&gt;
 * This class is a FilterInputStream descendant that reads from an underlying InputStream&lt;br /&gt;
 * up to a defined number of bytes or the end of the underlying stream. Closing this InputStream&lt;br /&gt;
 * will not result in the underlying InputStream to be closed, too.&lt;br /&gt;
 * &lt;br /&gt;
 * This InputStream can be used to read chunks from a larger file of which the length is&lt;br /&gt;
 * known in advance.&lt;br /&gt;
 */&lt;br /&gt;
public class SubInputStream extends FilterInputStream {&lt;br /&gt;
    /** Indicates the number of bytes remaining to be read from the underlying InputStream. */&lt;br /&gt;
    private long bytesToRead;&lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * Indicates whether the underlying stream should be closed when the {@link #close()} method&lt;br /&gt;
     * is called.&lt;br /&gt;
     */ &lt;br /&gt;
    private boolean closeUnderlying = false;&lt;br /&gt;
    &lt;br /&gt;
    /**&lt;br /&gt;
     * Creates a new SubInputStream.&lt;br /&gt;
     * @param in the InputStream to read from&lt;br /&gt;
     * @param maxLen the maximum number of bytes to read from the underlying InputStream until&lt;br /&gt;
     *               the end-of-file is signalled.&lt;br /&gt;
     * @param closeUnderlying true if the underlying stream should be closed when the&lt;br /&gt;
     *               {@link #close()} method is called.&lt;br /&gt;
     */&lt;br /&gt;
    public SubInputStream(InputStream in, long maxLen, boolean closeUnderlying) {&lt;br /&gt;
        super(in);&lt;br /&gt;
        this.bytesToRead = maxLen;&lt;br /&gt;
        this.closeUnderlying = closeUnderlying;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Creates a new SubInputStream. The underlying stream is not closed, when close() is called.&lt;br /&gt;
     * @param in the InputStream to read from&lt;br /&gt;
     * @param maxLen the maximum number of bytes to read from the underlying InputStream until&lt;br /&gt;
     *               the end-of-file is signalled.&lt;br /&gt;
     */&lt;br /&gt;
    public SubInputStream(InputStream in, long maxLen) {&lt;br /&gt;
        this(in, maxLen, false);&lt;br /&gt;
    }&lt;br /&gt;
    /** {@inheritDoc} */&lt;br /&gt;
    public int read() throws IOException {&lt;br /&gt;
        if (bytesToRead &amp;gt; 0) {&lt;br /&gt;
            int result = super.read();&lt;br /&gt;
            if (result &amp;gt;= 0) {&lt;br /&gt;
                bytesToRead--;&lt;br /&gt;
                return result;&lt;br /&gt;
            } else {&lt;br /&gt;
                return -1;&lt;br /&gt;
            }&lt;br /&gt;
        } else {&lt;br /&gt;
            return -1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    /** {@inheritDoc} */&lt;br /&gt;
    public int read(byte[] b, int off, int len) throws IOException {&lt;br /&gt;
        if (bytesToRead == 0) {&lt;br /&gt;
            return -1;&lt;br /&gt;
        }&lt;br /&gt;
        int effRead = (int)Math.min(bytesToRead, len);&lt;br /&gt;
        //cast to int is safe because len can never be bigger than Integer.MAX_VALUE&lt;br /&gt;
        &lt;br /&gt;
        int result = super.read(b, off, effRead);&lt;br /&gt;
        if (result &amp;gt;= 0) {&lt;br /&gt;
            bytesToRead -= result;&lt;br /&gt;
        }&lt;br /&gt;
        return result;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    /** {@inheritDoc} */&lt;br /&gt;
    public long skip(long n) throws IOException {&lt;br /&gt;
        long effRead = Math.min(bytesToRead, n);&lt;br /&gt;
        long result = super.skip(effRead);&lt;br /&gt;
        bytesToRead -= result;&lt;br /&gt;
        return result;&lt;br /&gt;
    }&lt;br /&gt;
    /** {@inheritDoc} */&lt;br /&gt;
    public void close() throws IOException {&lt;br /&gt;
        this.bytesToRead = 0;&lt;br /&gt;
        if (this.closeUnderlying) {&lt;br /&gt;
            super.close();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&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;
/* $Id: SubInputStreamTestCase.java 604883 2007-12-17 14:36:37Z jeremias $ */&lt;br /&gt;
 &lt;br /&gt;
package org.apache.xmlgraphics.util.io;&lt;br /&gt;
import java.io.ByteArrayInputStream;&lt;br /&gt;
import java.util.Arrays;&lt;br /&gt;
import junit.framework.TestCase;&lt;br /&gt;
/**&lt;br /&gt;
 * Test case for SubInputStream.&lt;br /&gt;
 */&lt;br /&gt;
public class SubInputStreamTestCase extends TestCase {&lt;br /&gt;
    /**&lt;br /&gt;
     * Main constructor.&lt;br /&gt;
     * @param name the test case&amp;quot;s name&lt;br /&gt;
     * @see junit.framework.TestCase#TestCase(String)&lt;br /&gt;
     */&lt;br /&gt;
    public SubInputStreamTestCase(String name) {&lt;br /&gt;
        super(name);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Tests SubInputStream.&lt;br /&gt;
     * @throws Exception if an error occurs&lt;br /&gt;
     */&lt;br /&gt;
    public void testMain() throws Exception {&lt;br /&gt;
        //Initialize test data&lt;br /&gt;
        byte[] data = new byte[256];&lt;br /&gt;
        for (int i = 0; i &amp;lt; data.length; i++) {&lt;br /&gt;
            data[i] = (byte)(i &amp;amp; 0xff);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        int v, c;&lt;br /&gt;
        byte[] buf;&lt;br /&gt;
        String s;&lt;br /&gt;
        &lt;br /&gt;
        SubInputStream subin = new SubInputStream(new ByteArrayInputStream(data), 10);&lt;br /&gt;
        v = subin.read();&lt;br /&gt;
        assertEquals(0, v);&lt;br /&gt;
        v = subin.read();&lt;br /&gt;
        assertEquals(1, v);&lt;br /&gt;
        &lt;br /&gt;
        buf = new byte[4];&lt;br /&gt;
        c = subin.read(buf);&lt;br /&gt;
        assertEquals(4, c);&lt;br /&gt;
        s = new String(buf, &amp;quot;US-ASCII&amp;quot;);&lt;br /&gt;
        assertEquals(&amp;quot;\u0002\u0003\u0004\u0005&amp;quot;, s);&lt;br /&gt;
        &lt;br /&gt;
        Arrays.fill(buf, (byte)0);&lt;br /&gt;
        c = subin.read(buf, 2, 2);&lt;br /&gt;
        assertEquals(2, c);&lt;br /&gt;
        s = new String(buf, &amp;quot;US-ASCII&amp;quot;);&lt;br /&gt;
        assertEquals(&amp;quot;\u0000\u0000\u0006\u0007&amp;quot;, s);&lt;br /&gt;
        &lt;br /&gt;
        Arrays.fill(buf, (byte)0);&lt;br /&gt;
        c = subin.read(buf);&lt;br /&gt;
        assertEquals(2, c);&lt;br /&gt;
        s = new String(buf, &amp;quot;US-ASCII&amp;quot;);&lt;br /&gt;
        assertEquals(&amp;quot;\u0008\u0009\u0000\u0000&amp;quot;, s);&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>