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

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/File_Input_Output/StringReader&amp;diff=6157&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/StringReader&amp;diff=6157&amp;oldid=prev"/>
				<updated>2010-06-01T06:02:58Z</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/StringReader&amp;diff=6156&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/StringReader&amp;diff=6156&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;== Read InputStream to string ==&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.ByteArrayOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.io.OutputStream;&lt;br /&gt;
&lt;br /&gt;
/** Utility class for working with streams.&lt;br /&gt;
 */&lt;br /&gt;
public final class Streams {&lt;br /&gt;
  /**&lt;br /&gt;
   * This convenience method allows to read a&lt;br /&gt;
   * {@link org.apache.rumons.fileupload.FileItemStream}&amp;quot;s&lt;br /&gt;
   * content into a string. The platform&amp;quot;s default character encoding&lt;br /&gt;
   * is used for converting bytes into characters.&lt;br /&gt;
   * @param pStream The input stream to read.&lt;br /&gt;
   * @see #asString(InputStream, String)&lt;br /&gt;
   * @return The streams contents, as a string.&lt;br /&gt;
   * @throws IOException An I/O error occurred.&lt;br /&gt;
   */&lt;br /&gt;
  public static String asString(InputStream pStream) throws IOException {&lt;br /&gt;
      ByteArrayOutputStream baos = new ByteArrayOutputStream();&lt;br /&gt;
      copy(pStream, baos, true);&lt;br /&gt;
      return baos.toString();&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * This convenience method allows to read a&lt;br /&gt;
   * {@link org.apache.rumons.fileupload.FileItemStream}&amp;quot;s&lt;br /&gt;
   * content into a string, using the given character encoding.&lt;br /&gt;
   * @param pStream The input stream to read.&lt;br /&gt;
   * @param pEncoding The character encoding, typically &amp;quot;UTF-8&amp;quot;.&lt;br /&gt;
   * @see #asString(InputStream)&lt;br /&gt;
   * @return The streams contents, as a string.&lt;br /&gt;
   * @throws IOException An I/O error occurred.&lt;br /&gt;
   */&lt;br /&gt;
  public static String asString(InputStream pStream, String pEncoding)&lt;br /&gt;
          throws IOException {&lt;br /&gt;
      ByteArrayOutputStream baos = new ByteArrayOutputStream();&lt;br /&gt;
      copy(pStream, baos, true);&lt;br /&gt;
      return baos.toString(pEncoding);&lt;br /&gt;
  }&lt;br /&gt;
    /**&lt;br /&gt;
     * Default buffer size for use in&lt;br /&gt;
     * {@link #copy(InputStream, OutputStream, boolean)}.&lt;br /&gt;
     */&lt;br /&gt;
    private static final int DEFAULT_BUFFER_SIZE = 8192;&lt;br /&gt;
    /**&lt;br /&gt;
     * Copies the contents of the given {@link InputStream}&lt;br /&gt;
     * to the given {@link OutputStream}. Shortcut for&lt;br /&gt;
     * &amp;lt;pre&amp;gt;&lt;br /&gt;
     *   copy(pInputStream, pOutputStream, new byte[8192]);&lt;br /&gt;
     * &amp;lt;/pre&amp;gt;&lt;br /&gt;
     * @param pInputStream The input stream, which is being read.&lt;br /&gt;
     * It is guaranteed, that {@link InputStream#close()} is called&lt;br /&gt;
     * on the stream.&lt;br /&gt;
     * @param pOutputStream The output stream, to which data should&lt;br /&gt;
     * be written. May be null, in which case the input streams&lt;br /&gt;
     * contents are simply discarded.&lt;br /&gt;
     * @param pClose True guarantees, that {@link OutputStream#close()}&lt;br /&gt;
     * is called on the stream. False indicates, that only&lt;br /&gt;
     * {@link OutputStream#flush()} should be called finally.&lt;br /&gt;
     *&lt;br /&gt;
     * @return Number of bytes, which have been copied.&lt;br /&gt;
     * @throws IOException An I/O error occurred.&lt;br /&gt;
     */&lt;br /&gt;
    public static long copy(InputStream pInputStream,&lt;br /&gt;
            OutputStream pOutputStream, boolean pClose)&lt;br /&gt;
            throws IOException {&lt;br /&gt;
        return copy(pInputStream, pOutputStream, pClose,&lt;br /&gt;
                new byte[DEFAULT_BUFFER_SIZE]);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Copies the contents of the given {@link InputStream}&lt;br /&gt;
     * to the given {@link OutputStream}.&lt;br /&gt;
     * @param pIn The input stream, which is being read.&lt;br /&gt;
     *   It is guaranteed, that {@link InputStream#close()} is called&lt;br /&gt;
     *   on the stream.&lt;br /&gt;
     * @param pOut The output stream, to which data should&lt;br /&gt;
     *   be written. May be null, in which case the input streams&lt;br /&gt;
     *   contents are simply discarded.&lt;br /&gt;
     * @param pClose True guarantees, that {@link OutputStream#close()}&lt;br /&gt;
     *   is called on the stream. False indicates, that only&lt;br /&gt;
     *   {@link OutputStream#flush()} should be called finally.&lt;br /&gt;
     * @param pBuffer Temporary buffer, which is to be used for&lt;br /&gt;
     *   copying data.&lt;br /&gt;
     * @return Number of bytes, which have been copied.&lt;br /&gt;
     * @throws IOException An I/O error occurred.&lt;br /&gt;
     */&lt;br /&gt;
    public static long copy(InputStream pIn,&lt;br /&gt;
            OutputStream pOut, boolean pClose,&lt;br /&gt;
            byte[] pBuffer)&lt;br /&gt;
    throws IOException {&lt;br /&gt;
        OutputStream out = pOut;&lt;br /&gt;
        InputStream in = pIn;&lt;br /&gt;
        try {&lt;br /&gt;
            long total = 0;&lt;br /&gt;
            for (;;) {&lt;br /&gt;
                int res = in.read(pBuffer);&lt;br /&gt;
                if (res == -1) {&lt;br /&gt;
                    break;&lt;br /&gt;
                }&lt;br /&gt;
                if (res &amp;gt; 0) {&lt;br /&gt;
                    total += res;&lt;br /&gt;
                    if (out != null) {&lt;br /&gt;
                        out.write(pBuffer, 0, res);&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            if (out != null) {&lt;br /&gt;
                if (pClose) {&lt;br /&gt;
                    out.close();&lt;br /&gt;
                } else {&lt;br /&gt;
                    out.flush();&lt;br /&gt;
                }&lt;br /&gt;
                out = null;&lt;br /&gt;
            }&lt;br /&gt;
            in.close();&lt;br /&gt;
            in = null;&lt;br /&gt;
            return total;&lt;br /&gt;
        } finally {&lt;br /&gt;
            if (in != null) {&lt;br /&gt;
                try {&lt;br /&gt;
                    in.close();&lt;br /&gt;
                } catch (Throwable t) {&lt;br /&gt;
                    /* Ignore me */&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            if (pClose  &amp;amp;&amp;amp;  out != null) {&lt;br /&gt;
                try {&lt;br /&gt;
                    out.close();&lt;br /&gt;
                } catch (Throwable t) {&lt;br /&gt;
                    /* Ignore me */&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Reads data off a stream, printing every byte read to System.err ==&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   *&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;
&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
/**&lt;br /&gt;
 * Reads data off a stream, printing every byte read to System.err.&lt;br /&gt;
 */&lt;br /&gt;
public class DebugInputStream extends InputStream {&lt;br /&gt;
    /**&lt;br /&gt;
     * The input stream being wrapped&lt;br /&gt;
     */&lt;br /&gt;
    InputStream in = null;&lt;br /&gt;
    /**&lt;br /&gt;
     * Constructor that takes an InputStream to be wrapped.&lt;br /&gt;
     *&lt;br /&gt;
     * @param in the InputStream to be wrapped&lt;br /&gt;
     */&lt;br /&gt;
    public DebugInputStream(InputStream in) {&lt;br /&gt;
        this.in = in;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Read a byte off the stream&lt;br /&gt;
     *&lt;br /&gt;
     * @return the byte read off the stream&lt;br /&gt;
     * @throws IOException if an exception is encountered when reading&lt;br /&gt;
     */&lt;br /&gt;
    public int read() throws IOException {&lt;br /&gt;
        int b = in.read();&lt;br /&gt;
        System.err.write(b);&lt;br /&gt;
        return b;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Close the stream&lt;br /&gt;
     *&lt;br /&gt;
     * @throws IOException if an exception is encountered when closing&lt;br /&gt;
     */&lt;br /&gt;
    public void close() throws IOException {&lt;br /&gt;
        in.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;
== Reads file contents ==&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;
 * The ObjectStyle Group Software License, version 1.1&lt;br /&gt;
 * ObjectStyle Group - http://objectstyle.org/&lt;br /&gt;
 * &lt;br /&gt;
 * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors&lt;br /&gt;
 * of the software. 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&lt;br /&gt;
 * are met:&lt;br /&gt;
 * &lt;br /&gt;
 * 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 * &lt;br /&gt;
 * 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer in&lt;br /&gt;
 *    the documentation and/or other materials provided with the&lt;br /&gt;
 *    distribution.&lt;br /&gt;
 * &lt;br /&gt;
 * 3. The end-user documentation included with the redistribution, if any,&lt;br /&gt;
 *    must include the following acknowlegement:&lt;br /&gt;
 *    &amp;quot;This product includes software developed by independent contributors&lt;br /&gt;
 *    and hosted on ObjectStyle Group web site (http://objectstyle.org/).&amp;quot;&lt;br /&gt;
 *    Alternately, this acknowlegement may appear in the software itself,&lt;br /&gt;
 *    if and wherever such third-party acknowlegements normally appear.&lt;br /&gt;
 * &lt;br /&gt;
 * 4. The names &amp;quot;ObjectStyle Group&amp;quot; and &amp;quot;Cayenne&amp;quot; must not be used to endorse&lt;br /&gt;
 *    or promote products derived from this software without prior written&lt;br /&gt;
 *    permission. For written permission, email&lt;br /&gt;
 *    &amp;quot;andrus at objectstyle dot org&amp;quot;.&lt;br /&gt;
 * &lt;br /&gt;
 * 5. Products derived from this software may not be called &amp;quot;ObjectStyle&amp;quot;&lt;br /&gt;
 *    or &amp;quot;Cayenne&amp;quot;, nor may &amp;quot;ObjectStyle&amp;quot; or &amp;quot;Cayenne&amp;quot; appear in their&lt;br /&gt;
 *    names without prior written permission.&lt;br /&gt;
 * &lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED ``AS IS&amp;quot;&amp;quot; AND ANY EXPRESSED OR IMPLIED&lt;br /&gt;
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES&lt;br /&gt;
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE&lt;br /&gt;
 * DISCLAIMED.  IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR&lt;br /&gt;
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,&lt;br /&gt;
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT&lt;br /&gt;
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF&lt;br /&gt;
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND&lt;br /&gt;
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,&lt;br /&gt;
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT&lt;br /&gt;
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF&lt;br /&gt;
 * SUCH DAMAGE.&lt;br /&gt;
 * &lt;br /&gt;
 * &lt;br /&gt;
 * This software consists of voluntary contributions made by many&lt;br /&gt;
 * individuals and hosted on ObjectStyle Group web site.  For more&lt;br /&gt;
 * information on the ObjectStyle Group, please see&lt;br /&gt;
 * &amp;lt;http://objectstyle.org/&amp;gt;.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.BufferedInputStream;&lt;br /&gt;
import java.io.BufferedOutputStream;&lt;br /&gt;
import java.io.BufferedReader;&lt;br /&gt;
import java.io.ByteArrayInputStream;&lt;br /&gt;
import java.io.ByteArrayOutputStream;&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.FileReader;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.io.ObjectInputStream;&lt;br /&gt;
import java.io.ObjectOutputStream;&lt;br /&gt;
import java.io.OutputStream;&lt;br /&gt;
import java.io.Serializable;&lt;br /&gt;
import java.lang.reflect.Member;&lt;br /&gt;
import java.lang.reflect.Modifier;&lt;br /&gt;
import java.net.URL;&lt;br /&gt;
import java.sql.SQLException;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.Collection;&lt;br /&gt;
import java.util.Collections;&lt;br /&gt;
import java.util.ruparator;&lt;br /&gt;
import java.util.HashMap;&lt;br /&gt;
import java.util.Iterator;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
import java.util.Map;&lt;br /&gt;
import java.util.regex.Pattern;&lt;br /&gt;
import javax.xml.parsers.ParserConfigurationException;&lt;br /&gt;
import javax.xml.parsers.SAXParser;&lt;br /&gt;
import javax.xml.parsers.SAXParserFactory;&lt;br /&gt;
&lt;br /&gt;
import org.xml.sax.SAXException;&lt;br /&gt;
import org.xml.sax.XMLReader;&lt;br /&gt;
/**&lt;br /&gt;
 * Contains various unorganized static utility methods used across Cayenne.&lt;br /&gt;
 * &lt;br /&gt;
 * @author Andrei Adamchik&lt;br /&gt;
 */&lt;br /&gt;
public class Util {&lt;br /&gt;
    /**&lt;br /&gt;
     * Reads file contents, returning it as a String, using System default line separator.&lt;br /&gt;
     */&lt;br /&gt;
    public static String stringFromFile(File file) throws IOException {&lt;br /&gt;
        return stringFromFile(file, System.getProperty(&amp;quot;line.separator&amp;quot;));&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Reads file contents, returning it as a String, joining lines with provided&lt;br /&gt;
     * separator.&lt;br /&gt;
     */&lt;br /&gt;
    public static String stringFromFile(File file, String joinWith) throws IOException {&lt;br /&gt;
        StringBuffer buf = new StringBuffer();&lt;br /&gt;
        BufferedReader in = new BufferedReader(new FileReader(file));&lt;br /&gt;
        try {&lt;br /&gt;
            String line = null;&lt;br /&gt;
            while ((line = in.readLine()) != null) {&lt;br /&gt;
                buf.append(line).append(joinWith);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        finally {&lt;br /&gt;
            in.close();&lt;br /&gt;
        }&lt;br /&gt;
        return buf.toString();&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;
== 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;
/*&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;
 * &amp;lt;p&amp;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;
}&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 string from InputStream and Reader ==&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;
 * $RCSfile: StringIO.java,v $&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright (c) 2007 Sun Microsystems, Inc. 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&lt;br /&gt;
 * are met:&lt;br /&gt;
 *&lt;br /&gt;
 * - Redistribution of source code must retain the above copyright&lt;br /&gt;
 *   notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 * - Redistribution in binary form must reproduce the above copyright&lt;br /&gt;
 *   notice, this list of conditions and the following disclaimer in&lt;br /&gt;
 *   the documentation and/or other materials provided with the&lt;br /&gt;
 *   distribution.&lt;br /&gt;
 *&lt;br /&gt;
 * Neither the name of Sun Microsystems, Inc. or the names of&lt;br /&gt;
 * contributors may be used to endorse or promote products derived&lt;br /&gt;
 * from this software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is provided &amp;quot;AS IS,&amp;quot; without a warranty of any&lt;br /&gt;
 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND&lt;br /&gt;
 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,&lt;br /&gt;
 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY&lt;br /&gt;
 * EXCLUDED. SUN MICROSYSTEMS, INC. (&amp;quot;SUN&amp;quot;) AND ITS LICENSORS SHALL&lt;br /&gt;
 * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF&lt;br /&gt;
 * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS&lt;br /&gt;
 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR&lt;br /&gt;
 * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,&lt;br /&gt;
 * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND&lt;br /&gt;
 * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR&lt;br /&gt;
 * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE&lt;br /&gt;
 * POSSIBILITY OF SUCH DAMAGES.&lt;br /&gt;
 *&lt;br /&gt;
 * You acknowledge that this software is not designed, licensed or&lt;br /&gt;
 * intended for use in the design, construction, operation or&lt;br /&gt;
 * maintenance of any nuclear facility.&lt;br /&gt;
 *&lt;br /&gt;
 * $Revision: 1.4 $&lt;br /&gt;
 * $Date: 2007/02/09 17:20:42 $&lt;br /&gt;
 * $State: Exp $&lt;br /&gt;
 */&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileReader;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.io.InputStreamReader;&lt;br /&gt;
import java.io.Reader;&lt;br /&gt;
import java.net.URL;&lt;br /&gt;
/**&lt;br /&gt;
 * Utility class with static methods to read the entire contents of a&lt;br /&gt;
 * file, URL, InputStream, or Reader into a single String that is&lt;br /&gt;
 * returned to the user.&lt;br /&gt;
 *&lt;br /&gt;
 * @since Java 3D 1.4&lt;br /&gt;
 */&lt;br /&gt;
public class StringIO {&lt;br /&gt;
    /**&lt;br /&gt;
     * Read the entire contents of the specified file and return a&lt;br /&gt;
     * single String object containing the contents of the file.&lt;br /&gt;
     *&lt;br /&gt;
     * @param fileName the name of the file from which to read&lt;br /&gt;
     *&lt;br /&gt;
     * @return a String containing the contents of the input file&lt;br /&gt;
     *&lt;br /&gt;
     * @throws IOException if the specified file cannot be opened, or&lt;br /&gt;
     * if an I/O error occurs while reading the file&lt;br /&gt;
     */&lt;br /&gt;
    public static String readFully(String fileName) throws IOException {&lt;br /&gt;
  return readFully(new File(fileName));&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Read the entire contents of the specified file and return a&lt;br /&gt;
     * single String object containing the contents of the file.&lt;br /&gt;
     * This method does not return until the end of the input file&lt;br /&gt;
     * is reached.&lt;br /&gt;
     *&lt;br /&gt;
     * @param file a File from which to read&lt;br /&gt;
     *&lt;br /&gt;
     * @return a String containing the contents of the input file&lt;br /&gt;
     *&lt;br /&gt;
     * @throws IOException if the specified file cannot be opened, or&lt;br /&gt;
     * if an I/O error occurs while reading the file&lt;br /&gt;
     */&lt;br /&gt;
    public static String readFully(File file) throws IOException {&lt;br /&gt;
  return readFully(new FileReader(file));&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Read the entire contents of the specified URL and return a&lt;br /&gt;
     * single String object containing the contents of the URL.&lt;br /&gt;
     * This method does not return until an end of stream is reached&lt;br /&gt;
     * for the URL.&lt;br /&gt;
     *&lt;br /&gt;
     * @param url a URL from which to read&lt;br /&gt;
     *&lt;br /&gt;
     * @return a String containing the contents of the input URL&lt;br /&gt;
     *&lt;br /&gt;
     * @throws IOException if the specified URL cannot be opened, or&lt;br /&gt;
     * if an I/O error occurs while reading the URL&lt;br /&gt;
     */&lt;br /&gt;
    public static String readFully(URL url) throws IOException {&lt;br /&gt;
  return readFully(url.openStream());&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Read the entire contents of the specified InputStream and return a&lt;br /&gt;
     * single String object containing the contents of the InputStream.&lt;br /&gt;
     * This method does not return until the end of the input&lt;br /&gt;
     * stream is reached.&lt;br /&gt;
     *&lt;br /&gt;
     * @param stream an InputStream from which to read&lt;br /&gt;
     *&lt;br /&gt;
     * @return a String containing the contents of the input stream&lt;br /&gt;
     *&lt;br /&gt;
     * @throws IOException if an I/O error occurs while reading the input stream&lt;br /&gt;
     */&lt;br /&gt;
    public static String readFully(InputStream stream) throws IOException {&lt;br /&gt;
  return readFully(new InputStreamReader(stream));&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Read the entire contents of the specified Reader and return a&lt;br /&gt;
     * single String object containing the contents of the InputStream.&lt;br /&gt;
     * This method does not return until the end of the input file or&lt;br /&gt;
     * stream is reached.&lt;br /&gt;
     *&lt;br /&gt;
     * @param reader a Reader from which to read&lt;br /&gt;
     *&lt;br /&gt;
     * @return a String containing the contents of the stream&lt;br /&gt;
     *&lt;br /&gt;
     * @throws IOException if an I/O error occurs while reading the input stream&lt;br /&gt;
     */&lt;br /&gt;
    public static String readFully(Reader reader) throws IOException {&lt;br /&gt;
  char[] arr = new char[8*1024]; // 8K at a time&lt;br /&gt;
  StringBuffer buf = new StringBuffer();&lt;br /&gt;
  int numChars;&lt;br /&gt;
  while ((numChars = reader.read(arr, 0, arr.length)) &amp;gt; 0) {&lt;br /&gt;
      buf.append(arr, 0, numChars);&lt;br /&gt;
  }&lt;br /&gt;
  return buf.toString();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Do not construct an instance of this class.&lt;br /&gt;
     */&lt;br /&gt;
    private StringIO() {&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 the StringReader class ==&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.StreamTokenizer;&lt;br /&gt;
import java.io.StringReader;&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] args) throws Exception{&lt;br /&gt;
    StringReader reader = new StringReader(&amp;quot;this is a test&amp;quot;);&lt;br /&gt;
    int wordCount = 0;&lt;br /&gt;
    StreamTokenizer streamTokenizer = new StreamTokenizer(reader);&lt;br /&gt;
    while (streamTokenizer.nextToken() != StreamTokenizer.TT_EOF) {&lt;br /&gt;
      if (streamTokenizer.ttype == StreamTokenizer.TT_WORD)&lt;br /&gt;
        wordCount++;&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(&amp;quot;Number of words in file: &amp;quot; + wordCount);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
//Number of words in file: 4&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>