You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/08/18 03:45:39 UTC
svn commit: r432462 [20/21] -
/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Reader.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Reader.java?rev=432462&r1=432461&r2=432462&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Reader.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Reader.java Thu Aug 17 18:45:35 2006
@@ -1,260 +1,260 @@
-/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package java.io;
-
-import java.nio.CharBuffer;
-
-/**
- * Reader is an Abstract class for reading Character Streams. Subclasses of
- * Reader must implement the methods <code>read(char[], int, int)</code> and
- * <code>close()</code>.
- *
- * @see Writer
- */
-public abstract class Reader implements Readable, Closeable {
- /**
- * The object used to synchronize access to the reader.
- */
- protected Object lock;
-
- /**
- * Constructs a new character stream Reader using <code>this</code> as the
- * Object to synchronize critical regions around.
- */
- protected Reader() {
- super();
- lock = this;
- }
-
- /**
- * Constructs a new character stream Reader using <code>lock</code> as the
- * Object to synchronize critical regions around.
- *
- * @param lock
- * the <code>Object</code> to synchronize critical regions
- * around.
- */
- protected Reader(Object lock) {
- if (lock != null)
- this.lock = lock;
- else
- throw new NullPointerException();
- }
-
- /**
- * Close this Reader. This must be implemented by any concrete subclasses.
- * The implementation should free any resources associated with the Reader.
- *
- * @throws IOException
- * If an error occurs attempting to close this Reader.
- */
- public abstract void close() throws IOException;
-
- /**
- * Set a Mark position in this Reader. The parameter <code>readLimit</code>
- * indicates how many characters can be read before a mark is invalidated.
- * Sending reset() will reposition the reader back to the marked position
- * provided <code>readLimit</code> has not been surpassed.
- * <p>
- * This default implementation simply throws IOException and concrete
- * subclasses must provide their own implementations.
- *
- * @param readLimit
- * an int representing how many characters must be read before
- * invalidating the mark.
- *
- * @throws IOException
- * If an error occurs attempting mark this Reader.
- */
- public void mark(int readLimit) throws IOException {
- throw new IOException();
- }
-
- /**
- * Answers a boolean indicating whether or not this Reader supports mark()
- * and reset(). This class a default implementation which answers false.
- *
- * @return <code>true</code> if mark() and reset() are supported,
- * <code>false</code> otherwise. This implementation returns
- * <code>false</code>.
- */
- public boolean markSupported() {
- return false;
- }
-
- /**
- * Reads a single character from this reader and returns the result as an
- * int. The 2 higher-order characters are set to 0. If the end of reader was
- * encountered then return -1.
- *
- * @return the character read or -1 if end of reader.
- *
- * @throws IOException
- * If the Reader is already closed or some other IO error
- * occurs.
- */
- public int read() throws IOException {
- synchronized (lock) {
- char charArray[] = new char[1];
- if (read(charArray, 0, 1) != -1)
- return charArray[0];
- return -1;
- }
- }
-
- /**
- * Reads characters from this Reader and stores them in the character array
- * <code>buf</code> starting at offset 0. Returns the number of characters
- * actually read or -1 if the end of reader was encountered.
- *
- * @param buf
- * character array to store the read characters
- * @return how many characters were successfully read in or else -1 if the
- * end of the reader was detected.
- *
- * @throws IOException
- * If the Reader is already closed or some other IO error
- * occurs.
- */
- public int read(char buf[]) throws IOException {
- return read(buf, 0, buf.length);
- }
-
- /**
- * Reads at most <code>count</code> characters from this Reader and stores
- * them at <code>offset</code> in the character array <code>buf</code>.
- * Returns the number of characters actually read or -1 if the end of reader
- * was encountered.
- *
- * @param buf
- * character array to store the read characters
- * @param offset
- * offset in buf to store the read characters
- * @param count
- * how many characters should be read in
- * @return how many characters were successfully read in or else -1 if the
- * end of the reader was detected.
- *
- * @throws IOException
- * If the Reader is already closed or some other IO error
- * occurs.
- */
- public abstract int read(char buf[], int offset, int count)
- throws IOException;
-
- /**
- * Answers a <code>boolean</code> indicating whether or not this Reader is
- * ready to be read without blocking. If the result is <code>true</code>,
- * the next <code>read()</code> will not block. If the result is
- * <code>false</code> this Reader may or may not block when
- * <code>read()</code> is sent.
- *
- * @return <code>true</code> if the receiver will not block when
- * <code>read()</code> is called, <code>false</code> if unknown
- * or blocking will occur.
- *
- * @throws IOException
- * If the Reader is already closed or some other IO error
- * occurs.
- */
- public boolean ready() throws IOException {
- return false;
- }
-
- /**
- * Reset this Readers position to the last <code>mark()</code> location.
- * Invocations of <code>read()/skip()</code> will occur from this new
- * location. If this Reader was not marked, the implementation of
- * <code>reset()</code> is implementation specific. See the comment for
- * the specific Reader subclass for implementation details. The default
- * action is to throw <code>IOException</code>.
- *
- * @throws IOException
- * If a problem occured or the receiver does not support
- * <code>mark()/reset()</code>.
- */
- public void reset() throws IOException {
- throw new IOException();
- }
-
- /**
- * Skips <code>count</code> number of characters in this Reader.
- * Subsequent <code>read()</code>'s will not return these characters
- * unless <code>reset()</code> is used. This method may perform multiple
- * reads to read <code>count</code> characters.
- *
- * @param count
- * how many characters should be passed over
- * @return how many characters were successfully passed over
- *
- * @throws IOException
- * If the Reader is closed when the call is made or if an IO
- * error occurs during the operation.
- */
- public long skip(long count) throws IOException {
- if (count >= 0) {
- synchronized (lock) {
- long skipped = 0;
- int toRead = count < 512 ? (int) count : 512;
- char charsSkipped[] = new char[toRead];
- while (skipped < count) {
- int read = read(charsSkipped, 0, toRead);
- if (read == -1) {
- return skipped;
- }
- skipped += read;
- if (read < toRead) {
- return skipped;
- }
- if (count - skipped < toRead) {
- toRead = (int) (count - skipped);
- }
- }
- return skipped;
- }
- }
- throw new IllegalArgumentException();
- }
-
- /**
- * Read chars from the Reader and then put them to the <code>target</code>
- * CharBuffer. Only put method is called on the <code>target</code>.
- *
- * @param target
- * the destination CharBuffer
- * @return the actual number of chars put to the <code>target</code>. -1
- * when the Reader has reached the end before the method is called.
- * @throws IOException
- * if any I/O error raises in the procedure
- * @throws NullPointerException
- * if the target CharBuffer is null
- * @throws ReadOnlyBufferException
- * if the target CharBuffer is readonly
- *
- */
- public int read(CharBuffer target) throws IOException {
- if (null == target) {
- throw new NullPointerException();
- }
- int length = target.length();
- char[] buf = new char[length];
- length = Math.min(length, read(buf));
- if (length > 0) {
- target.put(buf, 0, length);
- }
- return length;
- }
-}
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.io;
+
+import java.nio.CharBuffer;
+
+/**
+ * Reader is an Abstract class for reading Character Streams. Subclasses of
+ * Reader must implement the methods <code>read(char[], int, int)</code> and
+ * <code>close()</code>.
+ *
+ * @see Writer
+ */
+public abstract class Reader implements Readable, Closeable {
+ /**
+ * The object used to synchronize access to the reader.
+ */
+ protected Object lock;
+
+ /**
+ * Constructs a new character stream Reader using <code>this</code> as the
+ * Object to synchronize critical regions around.
+ */
+ protected Reader() {
+ super();
+ lock = this;
+ }
+
+ /**
+ * Constructs a new character stream Reader using <code>lock</code> as the
+ * Object to synchronize critical regions around.
+ *
+ * @param lock
+ * the <code>Object</code> to synchronize critical regions
+ * around.
+ */
+ protected Reader(Object lock) {
+ if (lock != null)
+ this.lock = lock;
+ else
+ throw new NullPointerException();
+ }
+
+ /**
+ * Close this Reader. This must be implemented by any concrete subclasses.
+ * The implementation should free any resources associated with the Reader.
+ *
+ * @throws IOException
+ * If an error occurs attempting to close this Reader.
+ */
+ public abstract void close() throws IOException;
+
+ /**
+ * Set a Mark position in this Reader. The parameter <code>readLimit</code>
+ * indicates how many characters can be read before a mark is invalidated.
+ * Sending reset() will reposition the reader back to the marked position
+ * provided <code>readLimit</code> has not been surpassed.
+ * <p>
+ * This default implementation simply throws IOException and concrete
+ * subclasses must provide their own implementations.
+ *
+ * @param readLimit
+ * an int representing how many characters must be read before
+ * invalidating the mark.
+ *
+ * @throws IOException
+ * If an error occurs attempting mark this Reader.
+ */
+ public void mark(int readLimit) throws IOException {
+ throw new IOException();
+ }
+
+ /**
+ * Answers a boolean indicating whether or not this Reader supports mark()
+ * and reset(). This class a default implementation which answers false.
+ *
+ * @return <code>true</code> if mark() and reset() are supported,
+ * <code>false</code> otherwise. This implementation returns
+ * <code>false</code>.
+ */
+ public boolean markSupported() {
+ return false;
+ }
+
+ /**
+ * Reads a single character from this reader and returns the result as an
+ * int. The 2 higher-order characters are set to 0. If the end of reader was
+ * encountered then return -1.
+ *
+ * @return the character read or -1 if end of reader.
+ *
+ * @throws IOException
+ * If the Reader is already closed or some other IO error
+ * occurs.
+ */
+ public int read() throws IOException {
+ synchronized (lock) {
+ char charArray[] = new char[1];
+ if (read(charArray, 0, 1) != -1)
+ return charArray[0];
+ return -1;
+ }
+ }
+
+ /**
+ * Reads characters from this Reader and stores them in the character array
+ * <code>buf</code> starting at offset 0. Returns the number of characters
+ * actually read or -1 if the end of reader was encountered.
+ *
+ * @param buf
+ * character array to store the read characters
+ * @return how many characters were successfully read in or else -1 if the
+ * end of the reader was detected.
+ *
+ * @throws IOException
+ * If the Reader is already closed or some other IO error
+ * occurs.
+ */
+ public int read(char buf[]) throws IOException {
+ return read(buf, 0, buf.length);
+ }
+
+ /**
+ * Reads at most <code>count</code> characters from this Reader and stores
+ * them at <code>offset</code> in the character array <code>buf</code>.
+ * Returns the number of characters actually read or -1 if the end of reader
+ * was encountered.
+ *
+ * @param buf
+ * character array to store the read characters
+ * @param offset
+ * offset in buf to store the read characters
+ * @param count
+ * how many characters should be read in
+ * @return how many characters were successfully read in or else -1 if the
+ * end of the reader was detected.
+ *
+ * @throws IOException
+ * If the Reader is already closed or some other IO error
+ * occurs.
+ */
+ public abstract int read(char buf[], int offset, int count)
+ throws IOException;
+
+ /**
+ * Answers a <code>boolean</code> indicating whether or not this Reader is
+ * ready to be read without blocking. If the result is <code>true</code>,
+ * the next <code>read()</code> will not block. If the result is
+ * <code>false</code> this Reader may or may not block when
+ * <code>read()</code> is sent.
+ *
+ * @return <code>true</code> if the receiver will not block when
+ * <code>read()</code> is called, <code>false</code> if unknown
+ * or blocking will occur.
+ *
+ * @throws IOException
+ * If the Reader is already closed or some other IO error
+ * occurs.
+ */
+ public boolean ready() throws IOException {
+ return false;
+ }
+
+ /**
+ * Reset this Readers position to the last <code>mark()</code> location.
+ * Invocations of <code>read()/skip()</code> will occur from this new
+ * location. If this Reader was not marked, the implementation of
+ * <code>reset()</code> is implementation specific. See the comment for
+ * the specific Reader subclass for implementation details. The default
+ * action is to throw <code>IOException</code>.
+ *
+ * @throws IOException
+ * If a problem occured or the receiver does not support
+ * <code>mark()/reset()</code>.
+ */
+ public void reset() throws IOException {
+ throw new IOException();
+ }
+
+ /**
+ * Skips <code>count</code> number of characters in this Reader.
+ * Subsequent <code>read()</code>'s will not return these characters
+ * unless <code>reset()</code> is used. This method may perform multiple
+ * reads to read <code>count</code> characters.
+ *
+ * @param count
+ * how many characters should be passed over
+ * @return how many characters were successfully passed over
+ *
+ * @throws IOException
+ * If the Reader is closed when the call is made or if an IO
+ * error occurs during the operation.
+ */
+ public long skip(long count) throws IOException {
+ if (count >= 0) {
+ synchronized (lock) {
+ long skipped = 0;
+ int toRead = count < 512 ? (int) count : 512;
+ char charsSkipped[] = new char[toRead];
+ while (skipped < count) {
+ int read = read(charsSkipped, 0, toRead);
+ if (read == -1) {
+ return skipped;
+ }
+ skipped += read;
+ if (read < toRead) {
+ return skipped;
+ }
+ if (count - skipped < toRead) {
+ toRead = (int) (count - skipped);
+ }
+ }
+ return skipped;
+ }
+ }
+ throw new IllegalArgumentException();
+ }
+
+ /**
+ * Read chars from the Reader and then put them to the <code>target</code>
+ * CharBuffer. Only put method is called on the <code>target</code>.
+ *
+ * @param target
+ * the destination CharBuffer
+ * @return the actual number of chars put to the <code>target</code>. -1
+ * when the Reader has reached the end before the method is called.
+ * @throws IOException
+ * if any I/O error raises in the procedure
+ * @throws NullPointerException
+ * if the target CharBuffer is null
+ * @throws ReadOnlyBufferException
+ * if the target CharBuffer is readonly
+ *
+ */
+ public int read(CharBuffer target) throws IOException {
+ if (null == target) {
+ throw new NullPointerException();
+ }
+ int length = target.length();
+ char[] buf = new char[length];
+ length = Math.min(length, read(buf));
+ if (length > 0) {
+ target.put(buf, 0, length);
+ }
+ return length;
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Reader.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SequenceInputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SequenceInputStream.java?rev=432462&r1=432461&r2=432462&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SequenceInputStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SequenceInputStream.java Thu Aug 17 18:45:35 2006
@@ -1,185 +1,185 @@
-/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package java.io;
-
-import java.util.Enumeration;
-import java.util.Vector;
-
-/**
- * SequenceInputStream is used for streaming over a sequence of streams
- * concatenated together. Reads are taken from the first stream until it ends,
- * then the next stream is used until the last stream returns end of file.
- *
- */
-public class SequenceInputStream extends InputStream {
- /**
- * An enumeration which will return types of InputStream.
- */
- Enumeration<? extends InputStream> e;
-
- /**
- * The current input stream.
- */
- InputStream in;
-
- /**
- * Constructs a new SequenceInputStream using the two streams
- * <code>s1</code> and <code>s2</code> as the sequence of streams to
- * read from.
- *
- * @param s1
- * the first stream to get bytes from
- * @param s2
- * the second stream to get bytes from
- */
- public SequenceInputStream(InputStream s1, InputStream s2) {
- if (s1 == null) {
- throw new NullPointerException();
- }
- Vector<InputStream> inVector = new Vector<InputStream>(1);
- inVector.addElement(s2);
- e = inVector.elements();
- in = s1;
- }
-
- /**
- * Constructs a new SequenceInputStream using the elements returned from
- * Enumeration <code>e</code> as the stream sequence. The types returned
- * from nextElement() must be of InputStream.
- *
- * @param e
- * the Enumeration of InputStreams to get bytes from
- */
- public SequenceInputStream(Enumeration<? extends InputStream> e) {
- this.e = e;
- if (e.hasMoreElements()) {
- in = e.nextElement();
- if (in == null) {
- throw new NullPointerException();
- }
- }
- }
-
- /**
- * Answers a int representing then number of bytes that are available before
- * this InputStream will block.
- *
- * @return the number of bytes available before blocking.
- *
- * @throws IOException
- * If an error occurs in this InputStream.
- */
- public int available() throws IOException {
- if (e != null && in != null) {
- return in.available();
- }
- return 0;
- }
-
- /**
- * Close the SequenceInputStream. All streams in this sequence are closed
- * before returning from this method. This stream cannot be used for input
- * once it has been closed.
- *
- * @throws IOException
- * If an error occurs attempting to close this FileInputStream.
- */
- public void close() throws IOException {
- while (in != null) {
- nextStream();
- }
- e = null;
- }
-
- /**
- * Sets up the next InputStream or leaves it alone if there are none left.
- *
- * @throws IOException
- */
- private void nextStream() throws IOException {
- if (in != null) {
- in.close();
- }
- if (e.hasMoreElements()) {
- in = e.nextElement();
- if (in == null) {
- throw new NullPointerException();
- }
- } else {
- in = null;
- }
- }
-
- /**
- * Reads a single byte from this SequenceInputStream and returns the result
- * as an int. The low-order byte is returned or -1 of the end of stream was
- * encountered. The current stream is read from. If it reaches the end of
- * file, the next stream is read from.
- *
- * @return the byte read or -1 if end of stream.
- *
- * @throws IOException
- * If an error occurs while reading the stream
- */
- public int read() throws IOException {
- while (in != null) {
- int result = in.read();
- if (result >= 0) {
- return result;
- }
- nextStream();
- }
- return -1;
- }
-
- /**
- * Reads at most <code>count</code> bytes from this SequenceInputStream
- * and stores them in byte array <code>buffer</code> starting at
- * <code>offset</code>. Answer the number of bytes actually read or -1 if
- * no bytes were read and end of stream was encountered.
- *
- * @param buffer
- * the byte array in which to store the read bytes.
- * @param offset
- * the offset in <code>buffer</code> to store the read bytes.
- * @param count
- * the maximum number of bytes to store in <code>buffer</code>.
- * @return the number of bytes actually read or -1 if end of stream.
- *
- * @throws IOException
- * If an error occurs while reading the stream
- */
- public int read(byte[] buffer, int offset, int count) throws IOException {
- if (in == null) {
- return -1;
- }
- if (buffer == null) {
- throw new NullPointerException();
- }
- // avoid int overflow
- if (offset < 0 || offset > buffer.length - count || count < 0) {
- throw new IndexOutOfBoundsException();
- }
- while (in != null) {
- int result = in.read(buffer, offset, count);
- if (result >= 0) {
- return result;
- }
- nextStream();
- }
- return -1;
- }
-}
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.io;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+/**
+ * SequenceInputStream is used for streaming over a sequence of streams
+ * concatenated together. Reads are taken from the first stream until it ends,
+ * then the next stream is used until the last stream returns end of file.
+ *
+ */
+public class SequenceInputStream extends InputStream {
+ /**
+ * An enumeration which will return types of InputStream.
+ */
+ Enumeration<? extends InputStream> e;
+
+ /**
+ * The current input stream.
+ */
+ InputStream in;
+
+ /**
+ * Constructs a new SequenceInputStream using the two streams
+ * <code>s1</code> and <code>s2</code> as the sequence of streams to
+ * read from.
+ *
+ * @param s1
+ * the first stream to get bytes from
+ * @param s2
+ * the second stream to get bytes from
+ */
+ public SequenceInputStream(InputStream s1, InputStream s2) {
+ if (s1 == null) {
+ throw new NullPointerException();
+ }
+ Vector<InputStream> inVector = new Vector<InputStream>(1);
+ inVector.addElement(s2);
+ e = inVector.elements();
+ in = s1;
+ }
+
+ /**
+ * Constructs a new SequenceInputStream using the elements returned from
+ * Enumeration <code>e</code> as the stream sequence. The types returned
+ * from nextElement() must be of InputStream.
+ *
+ * @param e
+ * the Enumeration of InputStreams to get bytes from
+ */
+ public SequenceInputStream(Enumeration<? extends InputStream> e) {
+ this.e = e;
+ if (e.hasMoreElements()) {
+ in = e.nextElement();
+ if (in == null) {
+ throw new NullPointerException();
+ }
+ }
+ }
+
+ /**
+ * Answers a int representing then number of bytes that are available before
+ * this InputStream will block.
+ *
+ * @return the number of bytes available before blocking.
+ *
+ * @throws IOException
+ * If an error occurs in this InputStream.
+ */
+ public int available() throws IOException {
+ if (e != null && in != null) {
+ return in.available();
+ }
+ return 0;
+ }
+
+ /**
+ * Close the SequenceInputStream. All streams in this sequence are closed
+ * before returning from this method. This stream cannot be used for input
+ * once it has been closed.
+ *
+ * @throws IOException
+ * If an error occurs attempting to close this FileInputStream.
+ */
+ public void close() throws IOException {
+ while (in != null) {
+ nextStream();
+ }
+ e = null;
+ }
+
+ /**
+ * Sets up the next InputStream or leaves it alone if there are none left.
+ *
+ * @throws IOException
+ */
+ private void nextStream() throws IOException {
+ if (in != null) {
+ in.close();
+ }
+ if (e.hasMoreElements()) {
+ in = e.nextElement();
+ if (in == null) {
+ throw new NullPointerException();
+ }
+ } else {
+ in = null;
+ }
+ }
+
+ /**
+ * Reads a single byte from this SequenceInputStream and returns the result
+ * as an int. The low-order byte is returned or -1 of the end of stream was
+ * encountered. The current stream is read from. If it reaches the end of
+ * file, the next stream is read from.
+ *
+ * @return the byte read or -1 if end of stream.
+ *
+ * @throws IOException
+ * If an error occurs while reading the stream
+ */
+ public int read() throws IOException {
+ while (in != null) {
+ int result = in.read();
+ if (result >= 0) {
+ return result;
+ }
+ nextStream();
+ }
+ return -1;
+ }
+
+ /**
+ * Reads at most <code>count</code> bytes from this SequenceInputStream
+ * and stores them in byte array <code>buffer</code> starting at
+ * <code>offset</code>. Answer the number of bytes actually read or -1 if
+ * no bytes were read and end of stream was encountered.
+ *
+ * @param buffer
+ * the byte array in which to store the read bytes.
+ * @param offset
+ * the offset in <code>buffer</code> to store the read bytes.
+ * @param count
+ * the maximum number of bytes to store in <code>buffer</code>.
+ * @return the number of bytes actually read or -1 if end of stream.
+ *
+ * @throws IOException
+ * If an error occurs while reading the stream
+ */
+ public int read(byte[] buffer, int offset, int count) throws IOException {
+ if (in == null) {
+ return -1;
+ }
+ if (buffer == null) {
+ throw new NullPointerException();
+ }
+ // avoid int overflow
+ if (offset < 0 || offset > buffer.length - count || count < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ while (in != null) {
+ int result = in.read(buffer, offset, count);
+ if (result >= 0) {
+ return result;
+ }
+ nextStream();
+ }
+ return -1;
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SequenceInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Serializable.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Serializable.java?rev=432462&r1=432461&r2=432462&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Serializable.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Serializable.java Thu Aug 17 18:45:35 2006
@@ -1,28 +1,28 @@
-/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package java.io;
-
-
-/**
- * Objects that want to be serialized/deserialized using
- * ObjectOutputStream/ObjectInputStream should implement this interface.
- *
- *
- */
-public interface Serializable {
- /* empty */
-}
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package java.io;
+
+
+/**
+ * Objects that want to be serialized/deserialized using
+ * ObjectOutputStream/ObjectInputStream should implement this interface.
+ *
+ *
+ */
+public interface Serializable {
+ /* empty */
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/Serializable.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SerializablePermission.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SerializablePermission.java?rev=432462&r1=432461&r2=432462&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SerializablePermission.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SerializablePermission.java Thu Aug 17 18:45:35 2006
@@ -1,62 +1,62 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package java.io;
-
-import java.security.BasicPermission;
-
-
-/**
- * SerializablePermission objects represent permission to access unsafe
- * serialization operations. The name of the permission should be one of:
- * <dl>
- * <dt>enableSubclassImplementation</dt>
- * <dd>Subclasses can override serialization behavior</dd>
- * <dt>enableSubstitution</dt>
- * <dd>Object substitution can be enabled</dd>
- * </dl>
- *
- * @see ObjectStreamConstants
- */
-public final class SerializablePermission extends BasicPermission {
- private static final long serialVersionUID = 8537212141160296410L;
-
- //Serializable field
- @SuppressWarnings("unused")
- private String actions;
-
- /**
- * Creates an instance of this class with the given name.
- *
- * @param permissionName
- * the name of the new permission.
- */
- public SerializablePermission(String permissionName) {
- super(permissionName);
- }
-
- /**
- * Creates an instance of this class with the given name and action list.
- * The action list is ignored.
- *
- * @param name
- * the name of the new permission.
- * @param actions
- * ignored.
- */
- public SerializablePermission(String name, String actions) {
- super(name, actions);
- }
-}
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.io;
+
+import java.security.BasicPermission;
+
+
+/**
+ * SerializablePermission objects represent permission to access unsafe
+ * serialization operations. The name of the permission should be one of:
+ * <dl>
+ * <dt>enableSubclassImplementation</dt>
+ * <dd>Subclasses can override serialization behavior</dd>
+ * <dt>enableSubstitution</dt>
+ * <dd>Object substitution can be enabled</dd>
+ * </dl>
+ *
+ * @see ObjectStreamConstants
+ */
+public final class SerializablePermission extends BasicPermission {
+ private static final long serialVersionUID = 8537212141160296410L;
+
+ //Serializable field
+ @SuppressWarnings("unused")
+ private String actions;
+
+ /**
+ * Creates an instance of this class with the given name.
+ *
+ * @param permissionName
+ * the name of the new permission.
+ */
+ public SerializablePermission(String permissionName) {
+ super(permissionName);
+ }
+
+ /**
+ * Creates an instance of this class with the given name and action list.
+ * The action list is ignored.
+ *
+ * @param name
+ * the name of the new permission.
+ * @param actions
+ * ignored.
+ */
+ public SerializablePermission(String name, String actions) {
+ super(name, actions);
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/SerializablePermission.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamCorruptedException.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamCorruptedException.java?rev=432462&r1=432461&r2=432462&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamCorruptedException.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamCorruptedException.java Thu Aug 17 18:45:35 2006
@@ -1,50 +1,50 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package java.io;
-
-
-/**
- * When readObject() cannot read an object from the input stream due to missing
- * information (cyclic reference that doesn't match previous instance or missing
- * class descriptor for instance to be loaded) this type of exception is thrown.
- *
- * @see ObjectInputStream
- * @see OptionalDataException
- *
- */
-public class StreamCorruptedException extends ObjectStreamException {
-
- private static final long serialVersionUID = 8983558202217591746L;
-
- /**
- * Constructs a new instance of this class with its walkback filled in.
- */
- public StreamCorruptedException() {
- super();
- }
-
- /**
- * Constructs a new instance of this class with its walkback and message
- * filled in.
- *
- * @param detailMessage
- * the detail message for the exception.
- */
- public StreamCorruptedException(String detailMessage) {
- super(detailMessage);
- }
-
-}
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.io;
+
+
+/**
+ * When readObject() cannot read an object from the input stream due to missing
+ * information (cyclic reference that doesn't match previous instance or missing
+ * class descriptor for instance to be loaded) this type of exception is thrown.
+ *
+ * @see ObjectInputStream
+ * @see OptionalDataException
+ *
+ */
+public class StreamCorruptedException extends ObjectStreamException {
+
+ private static final long serialVersionUID = 8983558202217591746L;
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ */
+ public StreamCorruptedException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * the detail message for the exception.
+ */
+ public StreamCorruptedException(String detailMessage) {
+ super(detailMessage);
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamCorruptedException.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamTokenizer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamTokenizer.java?rev=432462&r1=432461&r2=432462&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamTokenizer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamTokenizer.java Thu Aug 17 18:45:35 2006
@@ -1,632 +1,632 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package java.io;
-
-
-/**
- * StreamTokenizer takes a stream and a set of tokens and parses them one at a
- * time. The different types of tokens that can be found are numbers,
- * identifiers, quoted strings, and different comment styles.
- *
- */
-public class StreamTokenizer {
- /**
- * Contains a number if the current token is a number (<code>ttype</code>
- * is <code>TT_NUMBER</code>)
- */
- public double nval;
-
- /**
- * Contains a string if the current token is a word (<code>ttype</code>
- * is <code>TT_WORD</code>)
- */
- public String sval;
-
- /**
- * After calling <code>nextToken</code>, the field <code>ttype</code>
- * contains the type of token that has been read. When a single character is
- * read, it's integer value is used. For a quoted string, the value is the
- * quoted character. If not one of those, then it is one of the following:
- * <UL>
- * <LI> <code>TT_WORD</code> - the token is a word.</LI>
- * <LI> <code>TT_NUMBER</code> - the token is a number.</LI>
- * <LI> <code>TT_EOL</code> - the end of line has been reached. Depends on
- * whether <code>eolIsSignificant</code> is <code>true</code>.</LI>
- * <LI> <code>TT_EOF</code> - the end of the stream has been reached.</LI>
- * </UL>
- */
-
- /**
- * The constant representing end of stream.
- */
- public static final int TT_EOF = -1;
-
- /**
- * The constant representing end of line.
- */
- public static final int TT_EOL = '\n';
-
- /**
- * The constant representing a number token.
- */
- public static final int TT_NUMBER = -2;
-
- /**
- * The constant representing a word token.
- */
- public static final int TT_WORD = -3;
-
- /**
- * Internal representation of unknown state.
- */
- private static final int TT_UNKNOWN = -4;
-
- /**
- * The token type
- */
- public int ttype = TT_UNKNOWN;
-
- /**
- * Internal character meanings, 0 implies TOKEN_ORDINARY
- */
- private byte tokenTypes[] = new byte[256];
-
- private static final byte TOKEN_COMMENT = 1;
-
- private static final byte TOKEN_QUOTE = 2;
-
- private static final byte TOKEN_WHITE = 4;
-
- private static final byte TOKEN_WORD = 8;
-
- private static final byte TOKEN_DIGIT = 16;
-
- private int lineNumber = 1;
-
- private boolean forceLowercase = false;
-
- private boolean isEOLSignificant = false;
-
- private boolean slashStarComments = false;
-
- private boolean slashSlashComments = false;
-
- private boolean pushBackToken = false;
-
- private boolean lastCr = false;
-
- /* One of these will have the stream */
- private InputStream inStream;
-
- private Reader inReader;
-
- private int peekChar = -2;
-
- /**
- * Private constructor to initialize the default values according to the
- * specification.
- */
- private StreamTokenizer() {
- /**
- * Initialize the default state per specification. All byte values 'A'
- * through 'Z', 'a' through 'z', and '\u00A0' through '\u00FF' are
- * considered to be alphabetic.
- */
- wordChars('A', 'Z');
- wordChars('a', 'z');
- wordChars(160, 255);
- /**
- * All byte values '\u0000' through '\u0020' are considered to be white
- * space.
- */
- whitespaceChars(0, 32);
- /**
- * '/' is a comment character. Single quote '\'' and double quote '"'
- * are string quote characters.
- */
- commentChar('/');
- quoteChar('"');
- quoteChar('\'');
- /**
- * Numbers are parsed.
- */
- parseNumbers();
- /**
- * Ends of lines are treated as white space, not as separate tokens.
- * C-style and C++-style comments are not recognized. These are the
- * defaults and are not needed in constructor.
- */
- }
-
- /**
- * Construct a new StreamTokenizer on the InputStream is. This usage of this
- * method should be replaced with the constructor which takes a Reader.
- *
- * @param is
- * The InputStream to parse tokens on.
- *
- * @deprecated Use StreamTokenizer(Reader)
- */
- public StreamTokenizer(InputStream is) {
- this();
- if (is != null)
- inStream = is;
- else
- throw new NullPointerException();
- }
-
- /**
- * Construct a new StreamTokenizer on the Reader <code>r</code>.
- * Initialize the default state per specification.
- * <UL>
- * <LI>All byte values 'A' through 'Z', 'a' through 'z', and '\u00A0'
- * through '\u00FF' are considered to be alphabetic.</LI>
- * <LI>All byte values '\u0000' through '\u0020' are considered to be white
- * space. '/' is a comment character.</LI>
- * <LI>Single quote '\'' and double quote '"' are string quote characters.</LI>
- * <LI>Numbers are parsed.</LI>
- * <LI>Ends of lines are considered to be white space rather than separate
- * tokens.</LI>
- * <LI>C-style and C++-style comments are not recognized.</LI>
- * </UL>
- * These are the defaults and are not needed in constructor.
- *
- * @param r
- * The InputStream to parse tokens on.
- */
- public StreamTokenizer(Reader r) {
- this();
- if (r != null)
- inReader = r;
- else
- throw new NullPointerException();
- }
-
- /**
- * Set the character <code>ch</code> to be regarded as a comment
- * character.
- *
- * @param ch
- * The character to be considered a comment character.
- */
- public void commentChar(int ch) {
- if (0 <= ch && ch < tokenTypes.length)
- tokenTypes[ch] = TOKEN_COMMENT;
- }
-
- /**
- * Set a boolean indicating whether or not end of line is significant and
- * should be returned as <code>TT_EOF</code> in <code>ttype</code>.
- *
- * @param flag
- * <code>true</code> if EOL is significant, <code>false</code>
- * otherwise.
- */
- public void eolIsSignificant(boolean flag) {
- isEOLSignificant = flag;
- }
-
- /**
- * Answer the current line number.
- *
- * @return the current line number.
- */
- public int lineno() {
- return lineNumber;
- }
-
- /**
- * Set a boolean indicating whether or not tokens should be uppercased when
- * present in <code>sval</code>.
- *
- * @param flag
- * <code>true</code> if <code>sval</code> should be forced
- * uppercase, <code>false</code> otherwise.
- */
- public void lowerCaseMode(boolean flag) {
- forceLowercase = flag;
- }
-
- /**
- * Answer the next token type.
- *
- * @return The next token to be parsed.
- *
- * @throws IOException
- * If an IO error occurs while getting the token
- */
- public int nextToken() throws IOException {
- if (pushBackToken) {
- pushBackToken = false;
- if (ttype != TT_UNKNOWN)
- return ttype;
- }
- sval = null; // Always reset sval to null
- int currentChar = peekChar == -2 ? read() : peekChar;
-
- if (lastCr && currentChar == '\n') {
- lastCr = false;
- currentChar = read();
- }
- if (currentChar == -1)
- return (ttype = TT_EOF);
-
- byte currentType = currentChar > 255 ? TOKEN_WORD
- : tokenTypes[currentChar];
- while ((currentType & TOKEN_WHITE) != 0) {
- /**
- * Skip over white space until we hit a new line or a real token
- */
- if (currentChar == '\r') {
- lineNumber++;
- if (isEOLSignificant) {
- lastCr = true;
- peekChar = -2;
- return (ttype = TT_EOL);
- }
- if ((currentChar = read()) == '\n')
- currentChar = read();
- } else if (currentChar == '\n') {
- lineNumber++;
- if (isEOLSignificant) {
- peekChar = -2;
- return (ttype = TT_EOL);
- }
- currentChar = read();
- } else {
- // Advance over this white space character and try again.
- currentChar = read();
- }
- if (currentChar == -1)
- return (ttype = TT_EOF);
- currentType = currentChar > 255 ? TOKEN_WORD
- : tokenTypes[currentChar];
- }
-
- /**
- * Check for digits before checking for words since digits can be
- * contained within words.
- */
- if ((currentType & TOKEN_DIGIT) != 0) {
- StringBuilder digits = new StringBuilder(20);
- boolean haveDecimal = false, checkJustNegative = currentChar == '-';
- while (true) {
- if (currentChar == '.')
- haveDecimal = true;
- digits.append((char) currentChar);
- currentChar = read();
- if ((currentChar < '0' || currentChar > '9')
- && (haveDecimal || currentChar != '.'))
- break;
- }
- peekChar = currentChar;
- if (checkJustNegative && digits.length() == 1)
- // Didn't get any other digits other than '-'
- return (ttype = '-');
- try {
- nval = Double.valueOf(digits.toString()).doubleValue();
- } catch (NumberFormatException e) {
- // Unsure what to do, will write test.
- nval = 0;
- }
- return (ttype = TT_NUMBER);
- }
- // Check for words
- if ((currentType & TOKEN_WORD) != 0) {
- StringBuffer word = new StringBuffer(20);
- while (true) {
- word.append((char) currentChar);
- currentChar = read();
- if (currentChar == -1
- || (currentChar < 256 && (tokenTypes[currentChar] & (TOKEN_WORD | TOKEN_DIGIT)) == 0))
- break;
- }
- peekChar = currentChar;
- sval = forceLowercase ? word.toString().toLowerCase() : word
- .toString();
- return (ttype = TT_WORD);
- }
- // Check for quoted character
- if (currentType == TOKEN_QUOTE) {
- int matchQuote = currentChar;
- StringBuffer quoteString = new StringBuffer();
- int peekOne = read();
- while (peekOne >= 0 && peekOne != matchQuote && peekOne != '\r'
- && peekOne != '\n') {
- boolean readPeek = true;
- if (peekOne == '\\') {
- int c1 = read();
- // Check for quoted octal IE: \377
- if (c1 <= '7' && c1 >= '0') {
- int digitValue = c1 - '0';
- c1 = read();
- if (c1 > '7' || c1 < '0') {
- readPeek = false;
- } else {
- digitValue = digitValue * 8 + (c1 - '0');
- c1 = read();
- // limit the digit value to a byte
- if (digitValue > 037 || c1 > '7' || c1 < '0')
- readPeek = false;
- else
- digitValue = digitValue * 8 + (c1 - '0');
- }
- if (!readPeek) {
- // We've consumed one to many
- quoteString.append((char) digitValue);
- peekOne = c1;
- } else {
- peekOne = digitValue;
- }
- } else {
- switch (c1) {
- case 'a':
- peekOne = 0x7;
- break;
- case 'b':
- peekOne = 0x8;
- break;
- case 'f':
- peekOne = 0xc;
- break;
- case 'n':
- peekOne = 0xA;
- break;
- case 'r':
- peekOne = 0xD;
- break;
- case 't':
- peekOne = 0x9;
- break;
- case 'v':
- peekOne = 0xB;
- break;
- default:
- peekOne = c1;
- }
- }
- }
- if (readPeek) {
- quoteString.append((char) peekOne);
- peekOne = read();
- }
- }
- if (peekOne == matchQuote)
- peekOne = read();
- peekChar = peekOne;
- ttype = matchQuote;
- sval = quoteString.toString();
- return ttype;
- }
- // Check for comment character
- if (currentType == TOKEN_COMMENT) {
- // Skip to EOF or new line then return the next token
- while ((currentChar = read()) >= 0 && currentChar != '\r'
- && currentChar != '\n') {
- // Intentionally empty
- }
- peekChar = currentChar;
- return nextToken();
- }
- // Do comments, both "//" and "/*stuff*/"
- if (currentChar == '/' && (slashSlashComments || slashStarComments)) {
- if ((currentChar = read()) == '*' && slashStarComments) {
- int peekOne = read();
- while (true) {
- currentChar = peekOne;
- peekOne = read();
- if (currentChar == -1) {
- peekChar = -1;
- return (ttype = TT_EOF);
- }
- if (currentChar == '\r') {
- if (peekOne == '\n')
- peekOne = read();
- lineNumber++;
- } else if (currentChar == '\n') {
- lineNumber++;
- } else if (currentChar == '*' && peekOne == '/') {
- peekChar = read();
- return nextToken();
- }
- }
- } else if (currentChar == '/' && slashSlashComments) {
- // Skip to EOF or new line then return the next token
- while ((currentChar = read()) >= 0 && currentChar != '\r'
- && currentChar != '\n') {
- // Intentionally empty
- }
- peekChar = currentChar;
- return nextToken();
- } else {
- // Was just a slash by itself
- peekChar = currentChar;
- return (ttype = '/');
- }
- }
- peekChar = read();
- return (ttype = currentChar);
- }
-
- /**
- * Set the character <code>ch</code> to be regarded as an ordinary
- * character.
- *
- * @param ch
- * The character to be considered an ordinary comment character.
- */
- public void ordinaryChar(int ch) {
- if (0 <= ch && ch < tokenTypes.length)
- tokenTypes[ch] = 0;
- }
-
- /**
- * Set the characters ranging from <code>low</code> to <code>hi</code>
- * to be regarded as ordinary characters.
- *
- * @param low
- * The starting range for ordinary characters.
- * @param hi
- * The ending range for ordinary characters.
- */
- public void ordinaryChars(int low, int hi) {
- if (low < 0)
- low = 0;
- if (hi > tokenTypes.length)
- hi = tokenTypes.length - 1;
- for (int i = low; i <= hi; i++)
- tokenTypes[i] = 0;
- }
-
- /**
- * Indicate that numbers should be parsed.
- */
- public void parseNumbers() {
- for (int i = '0'; i <= '9'; i++)
- tokenTypes[i] |= TOKEN_DIGIT;
- tokenTypes['.'] |= TOKEN_DIGIT;
- tokenTypes['-'] |= TOKEN_DIGIT;
- }
-
- /**
- * Indicate that the current token should be pushed back and returned the
- * next time <code>nextToken()</code> is called.
- */
- public void pushBack() {
- pushBackToken = true;
- }
-
- /**
- * Set the character <code>ch</code> to be regarded as a quote character.
- *
- * @param ch
- * The character to be considered a quote comment character.
- */
- public void quoteChar(int ch) {
- if (0 <= ch && ch < tokenTypes.length)
- tokenTypes[ch] = TOKEN_QUOTE;
- }
-
- private int read() throws IOException {
- // Call the read for the appropriate stream
- if (inStream == null)
- return inReader.read();
- return inStream.read();
- }
-
- /**
- * Reset all characters so that they are ordinary.
- */
- public void resetSyntax() {
- for (int i = 0; i < 256; i++)
- tokenTypes[i] = 0;
- }
-
- /**
- * Set a boolean indicating whether or not slash slash comments should be
- * recognized. The comment ends at a new line.
- *
- * @param flag
- * <code>true</code> if <code>//</code> should be recognized
- * as the start of a comment, <code>false</code> otherwise.
- */
- public void slashSlashComments(boolean flag) {
- slashSlashComments = flag;
- }
-
- /**
- * Set a boolean indicating whether or not slash star comments should be
- * recognized. Slash-star comments cannot be nested and end when a
- * star-slash combination is found.
- *
- * @param flag
- * <code>true</code> if <code>/*</code> should be recognized
- * as the start of a comment, <code>false</code> otherwise.
- */
- public void slashStarComments(boolean flag) {
- slashStarComments = flag;
- }
-
- /**
- * Answer the state of this tokenizer in a readable format.
- *
- * @return The current state of this tokenizer.
- */
- public String toString() {
- // Values determined through experimentation
- StringBuilder result = new StringBuilder();
- result.append("Token["); //$NON-NLS-1$
- switch (ttype) {
- case TT_EOF:
- result.append("EOF"); //$NON-NLS-1$
- break;
- case TT_EOL:
- result.append("EOL"); //$NON-NLS-1$
- break;
- case TT_NUMBER:
- result.append("n="); //$NON-NLS-1$
- result.append(nval);
- break;
- case TT_WORD:
- result.append(sval);
- break;
- default:
- result.append('\'');
- result.append((char) ttype);
- result.append('\'');
- break;
- }
- result.append("], line "); //$NON-NLS-1$
- result.append(lineNumber);
- return result.toString();
- }
-
- /**
- * Set the characters ranging from <code>low</code> to <code>hi</code>
- * to be regarded as whitespace characters.
- *
- * @param low
- * The starting range for whitespace characters.
- * @param hi
- * The ending range for whitespace characters.
- */
- public void whitespaceChars(int low, int hi) {
- if (low < 0)
- low = 0;
- if (hi > tokenTypes.length)
- hi = tokenTypes.length - 1;
- for (int i = low; i <= hi; i++)
- tokenTypes[i] = TOKEN_WHITE;
- }
-
- /**
- * Set the characters ranging from <code>low</code> to <code>hi</code>
- * to be regarded as word characters.
- *
- * @param low
- * The starting range for word characters.
- * @param hi
- * The ending range for word characters.
- */
- public void wordChars(int low, int hi) {
- if (low < 0)
- low = 0;
- if (hi > tokenTypes.length)
- hi = tokenTypes.length - 1;
- for (int i = low; i <= hi; i++)
- tokenTypes[i] |= TOKEN_WORD;
- }
-}
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.io;
+
+
+/**
+ * StreamTokenizer takes a stream and a set of tokens and parses them one at a
+ * time. The different types of tokens that can be found are numbers,
+ * identifiers, quoted strings, and different comment styles.
+ *
+ */
+public class StreamTokenizer {
+ /**
+ * Contains a number if the current token is a number (<code>ttype</code>
+ * is <code>TT_NUMBER</code>)
+ */
+ public double nval;
+
+ /**
+ * Contains a string if the current token is a word (<code>ttype</code>
+ * is <code>TT_WORD</code>)
+ */
+ public String sval;
+
+ /**
+ * After calling <code>nextToken</code>, the field <code>ttype</code>
+ * contains the type of token that has been read. When a single character is
+ * read, it's integer value is used. For a quoted string, the value is the
+ * quoted character. If not one of those, then it is one of the following:
+ * <UL>
+ * <LI> <code>TT_WORD</code> - the token is a word.</LI>
+ * <LI> <code>TT_NUMBER</code> - the token is a number.</LI>
+ * <LI> <code>TT_EOL</code> - the end of line has been reached. Depends on
+ * whether <code>eolIsSignificant</code> is <code>true</code>.</LI>
+ * <LI> <code>TT_EOF</code> - the end of the stream has been reached.</LI>
+ * </UL>
+ */
+
+ /**
+ * The constant representing end of stream.
+ */
+ public static final int TT_EOF = -1;
+
+ /**
+ * The constant representing end of line.
+ */
+ public static final int TT_EOL = '\n';
+
+ /**
+ * The constant representing a number token.
+ */
+ public static final int TT_NUMBER = -2;
+
+ /**
+ * The constant representing a word token.
+ */
+ public static final int TT_WORD = -3;
+
+ /**
+ * Internal representation of unknown state.
+ */
+ private static final int TT_UNKNOWN = -4;
+
+ /**
+ * The token type
+ */
+ public int ttype = TT_UNKNOWN;
+
+ /**
+ * Internal character meanings, 0 implies TOKEN_ORDINARY
+ */
+ private byte tokenTypes[] = new byte[256];
+
+ private static final byte TOKEN_COMMENT = 1;
+
+ private static final byte TOKEN_QUOTE = 2;
+
+ private static final byte TOKEN_WHITE = 4;
+
+ private static final byte TOKEN_WORD = 8;
+
+ private static final byte TOKEN_DIGIT = 16;
+
+ private int lineNumber = 1;
+
+ private boolean forceLowercase = false;
+
+ private boolean isEOLSignificant = false;
+
+ private boolean slashStarComments = false;
+
+ private boolean slashSlashComments = false;
+
+ private boolean pushBackToken = false;
+
+ private boolean lastCr = false;
+
+ /* One of these will have the stream */
+ private InputStream inStream;
+
+ private Reader inReader;
+
+ private int peekChar = -2;
+
+ /**
+ * Private constructor to initialize the default values according to the
+ * specification.
+ */
+ private StreamTokenizer() {
+ /**
+ * Initialize the default state per specification. All byte values 'A'
+ * through 'Z', 'a' through 'z', and '\u00A0' through '\u00FF' are
+ * considered to be alphabetic.
+ */
+ wordChars('A', 'Z');
+ wordChars('a', 'z');
+ wordChars(160, 255);
+ /**
+ * All byte values '\u0000' through '\u0020' are considered to be white
+ * space.
+ */
+ whitespaceChars(0, 32);
+ /**
+ * '/' is a comment character. Single quote '\'' and double quote '"'
+ * are string quote characters.
+ */
+ commentChar('/');
+ quoteChar('"');
+ quoteChar('\'');
+ /**
+ * Numbers are parsed.
+ */
+ parseNumbers();
+ /**
+ * Ends of lines are treated as white space, not as separate tokens.
+ * C-style and C++-style comments are not recognized. These are the
+ * defaults and are not needed in constructor.
+ */
+ }
+
+ /**
+ * Construct a new StreamTokenizer on the InputStream is. This usage of this
+ * method should be replaced with the constructor which takes a Reader.
+ *
+ * @param is
+ * The InputStream to parse tokens on.
+ *
+ * @deprecated Use StreamTokenizer(Reader)
+ */
+ public StreamTokenizer(InputStream is) {
+ this();
+ if (is != null)
+ inStream = is;
+ else
+ throw new NullPointerException();
+ }
+
+ /**
+ * Construct a new StreamTokenizer on the Reader <code>r</code>.
+ * Initialize the default state per specification.
+ * <UL>
+ * <LI>All byte values 'A' through 'Z', 'a' through 'z', and '\u00A0'
+ * through '\u00FF' are considered to be alphabetic.</LI>
+ * <LI>All byte values '\u0000' through '\u0020' are considered to be white
+ * space. '/' is a comment character.</LI>
+ * <LI>Single quote '\'' and double quote '"' are string quote characters.</LI>
+ * <LI>Numbers are parsed.</LI>
+ * <LI>Ends of lines are considered to be white space rather than separate
+ * tokens.</LI>
+ * <LI>C-style and C++-style comments are not recognized.</LI>
+ * </UL>
+ * These are the defaults and are not needed in constructor.
+ *
+ * @param r
+ * The InputStream to parse tokens on.
+ */
+ public StreamTokenizer(Reader r) {
+ this();
+ if (r != null)
+ inReader = r;
+ else
+ throw new NullPointerException();
+ }
+
+ /**
+ * Set the character <code>ch</code> to be regarded as a comment
+ * character.
+ *
+ * @param ch
+ * The character to be considered a comment character.
+ */
+ public void commentChar(int ch) {
+ if (0 <= ch && ch < tokenTypes.length)
+ tokenTypes[ch] = TOKEN_COMMENT;
+ }
+
+ /**
+ * Set a boolean indicating whether or not end of line is significant and
+ * should be returned as <code>TT_EOF</code> in <code>ttype</code>.
+ *
+ * @param flag
+ * <code>true</code> if EOL is significant, <code>false</code>
+ * otherwise.
+ */
+ public void eolIsSignificant(boolean flag) {
+ isEOLSignificant = flag;
+ }
+
+ /**
+ * Answer the current line number.
+ *
+ * @return the current line number.
+ */
+ public int lineno() {
+ return lineNumber;
+ }
+
+ /**
+ * Set a boolean indicating whether or not tokens should be uppercased when
+ * present in <code>sval</code>.
+ *
+ * @param flag
+ * <code>true</code> if <code>sval</code> should be forced
+ * uppercase, <code>false</code> otherwise.
+ */
+ public void lowerCaseMode(boolean flag) {
+ forceLowercase = flag;
+ }
+
+ /**
+ * Answer the next token type.
+ *
+ * @return The next token to be parsed.
+ *
+ * @throws IOException
+ * If an IO error occurs while getting the token
+ */
+ public int nextToken() throws IOException {
+ if (pushBackToken) {
+ pushBackToken = false;
+ if (ttype != TT_UNKNOWN)
+ return ttype;
+ }
+ sval = null; // Always reset sval to null
+ int currentChar = peekChar == -2 ? read() : peekChar;
+
+ if (lastCr && currentChar == '\n') {
+ lastCr = false;
+ currentChar = read();
+ }
+ if (currentChar == -1)
+ return (ttype = TT_EOF);
+
+ byte currentType = currentChar > 255 ? TOKEN_WORD
+ : tokenTypes[currentChar];
+ while ((currentType & TOKEN_WHITE) != 0) {
+ /**
+ * Skip over white space until we hit a new line or a real token
+ */
+ if (currentChar == '\r') {
+ lineNumber++;
+ if (isEOLSignificant) {
+ lastCr = true;
+ peekChar = -2;
+ return (ttype = TT_EOL);
+ }
+ if ((currentChar = read()) == '\n')
+ currentChar = read();
+ } else if (currentChar == '\n') {
+ lineNumber++;
+ if (isEOLSignificant) {
+ peekChar = -2;
+ return (ttype = TT_EOL);
+ }
+ currentChar = read();
+ } else {
+ // Advance over this white space character and try again.
+ currentChar = read();
+ }
+ if (currentChar == -1)
+ return (ttype = TT_EOF);
+ currentType = currentChar > 255 ? TOKEN_WORD
+ : tokenTypes[currentChar];
+ }
+
+ /**
+ * Check for digits before checking for words since digits can be
+ * contained within words.
+ */
+ if ((currentType & TOKEN_DIGIT) != 0) {
+ StringBuilder digits = new StringBuilder(20);
+ boolean haveDecimal = false, checkJustNegative = currentChar == '-';
+ while (true) {
+ if (currentChar == '.')
+ haveDecimal = true;
+ digits.append((char) currentChar);
+ currentChar = read();
+ if ((currentChar < '0' || currentChar > '9')
+ && (haveDecimal || currentChar != '.'))
+ break;
+ }
+ peekChar = currentChar;
+ if (checkJustNegative && digits.length() == 1)
+ // Didn't get any other digits other than '-'
+ return (ttype = '-');
+ try {
+ nval = Double.valueOf(digits.toString()).doubleValue();
+ } catch (NumberFormatException e) {
+ // Unsure what to do, will write test.
+ nval = 0;
+ }
+ return (ttype = TT_NUMBER);
+ }
+ // Check for words
+ if ((currentType & TOKEN_WORD) != 0) {
+ StringBuffer word = new StringBuffer(20);
+ while (true) {
+ word.append((char) currentChar);
+ currentChar = read();
+ if (currentChar == -1
+ || (currentChar < 256 && (tokenTypes[currentChar] & (TOKEN_WORD | TOKEN_DIGIT)) == 0))
+ break;
+ }
+ peekChar = currentChar;
+ sval = forceLowercase ? word.toString().toLowerCase() : word
+ .toString();
+ return (ttype = TT_WORD);
+ }
+ // Check for quoted character
+ if (currentType == TOKEN_QUOTE) {
+ int matchQuote = currentChar;
+ StringBuffer quoteString = new StringBuffer();
+ int peekOne = read();
+ while (peekOne >= 0 && peekOne != matchQuote && peekOne != '\r'
+ && peekOne != '\n') {
+ boolean readPeek = true;
+ if (peekOne == '\\') {
+ int c1 = read();
+ // Check for quoted octal IE: \377
+ if (c1 <= '7' && c1 >= '0') {
+ int digitValue = c1 - '0';
+ c1 = read();
+ if (c1 > '7' || c1 < '0') {
+ readPeek = false;
+ } else {
+ digitValue = digitValue * 8 + (c1 - '0');
+ c1 = read();
+ // limit the digit value to a byte
+ if (digitValue > 037 || c1 > '7' || c1 < '0')
+ readPeek = false;
+ else
+ digitValue = digitValue * 8 + (c1 - '0');
+ }
+ if (!readPeek) {
+ // We've consumed one to many
+ quoteString.append((char) digitValue);
+ peekOne = c1;
+ } else {
+ peekOne = digitValue;
+ }
+ } else {
+ switch (c1) {
+ case 'a':
+ peekOne = 0x7;
+ break;
+ case 'b':
+ peekOne = 0x8;
+ break;
+ case 'f':
+ peekOne = 0xc;
+ break;
+ case 'n':
+ peekOne = 0xA;
+ break;
+ case 'r':
+ peekOne = 0xD;
+ break;
+ case 't':
+ peekOne = 0x9;
+ break;
+ case 'v':
+ peekOne = 0xB;
+ break;
+ default:
+ peekOne = c1;
+ }
+ }
+ }
+ if (readPeek) {
+ quoteString.append((char) peekOne);
+ peekOne = read();
+ }
+ }
+ if (peekOne == matchQuote)
+ peekOne = read();
+ peekChar = peekOne;
+ ttype = matchQuote;
+ sval = quoteString.toString();
+ return ttype;
+ }
+ // Check for comment character
+ if (currentType == TOKEN_COMMENT) {
+ // Skip to EOF or new line then return the next token
+ while ((currentChar = read()) >= 0 && currentChar != '\r'
+ && currentChar != '\n') {
+ // Intentionally empty
+ }
+ peekChar = currentChar;
+ return nextToken();
+ }
+ // Do comments, both "//" and "/*stuff*/"
+ if (currentChar == '/' && (slashSlashComments || slashStarComments)) {
+ if ((currentChar = read()) == '*' && slashStarComments) {
+ int peekOne = read();
+ while (true) {
+ currentChar = peekOne;
+ peekOne = read();
+ if (currentChar == -1) {
+ peekChar = -1;
+ return (ttype = TT_EOF);
+ }
+ if (currentChar == '\r') {
+ if (peekOne == '\n')
+ peekOne = read();
+ lineNumber++;
+ } else if (currentChar == '\n') {
+ lineNumber++;
+ } else if (currentChar == '*' && peekOne == '/') {
+ peekChar = read();
+ return nextToken();
+ }
+ }
+ } else if (currentChar == '/' && slashSlashComments) {
+ // Skip to EOF or new line then return the next token
+ while ((currentChar = read()) >= 0 && currentChar != '\r'
+ && currentChar != '\n') {
+ // Intentionally empty
+ }
+ peekChar = currentChar;
+ return nextToken();
+ } else {
+ // Was just a slash by itself
+ peekChar = currentChar;
+ return (ttype = '/');
+ }
+ }
+ peekChar = read();
+ return (ttype = currentChar);
+ }
+
+ /**
+ * Set the character <code>ch</code> to be regarded as an ordinary
+ * character.
+ *
+ * @param ch
+ * The character to be considered an ordinary comment character.
+ */
+ public void ordinaryChar(int ch) {
+ if (0 <= ch && ch < tokenTypes.length)
+ tokenTypes[ch] = 0;
+ }
+
+ /**
+ * Set the characters ranging from <code>low</code> to <code>hi</code>
+ * to be regarded as ordinary characters.
+ *
+ * @param low
+ * The starting range for ordinary characters.
+ * @param hi
+ * The ending range for ordinary characters.
+ */
+ public void ordinaryChars(int low, int hi) {
+ if (low < 0)
+ low = 0;
+ if (hi > tokenTypes.length)
+ hi = tokenTypes.length - 1;
+ for (int i = low; i <= hi; i++)
+ tokenTypes[i] = 0;
+ }
+
+ /**
+ * Indicate that numbers should be parsed.
+ */
+ public void parseNumbers() {
+ for (int i = '0'; i <= '9'; i++)
+ tokenTypes[i] |= TOKEN_DIGIT;
+ tokenTypes['.'] |= TOKEN_DIGIT;
+ tokenTypes['-'] |= TOKEN_DIGIT;
+ }
+
+ /**
+ * Indicate that the current token should be pushed back and returned the
+ * next time <code>nextToken()</code> is called.
+ */
+ public void pushBack() {
+ pushBackToken = true;
+ }
+
+ /**
+ * Set the character <code>ch</code> to be regarded as a quote character.
+ *
+ * @param ch
+ * The character to be considered a quote comment character.
+ */
+ public void quoteChar(int ch) {
+ if (0 <= ch && ch < tokenTypes.length)
+ tokenTypes[ch] = TOKEN_QUOTE;
+ }
+
+ private int read() throws IOException {
+ // Call the read for the appropriate stream
+ if (inStream == null)
+ return inReader.read();
+ return inStream.read();
+ }
+
+ /**
+ * Reset all characters so that they are ordinary.
+ */
+ public void resetSyntax() {
+ for (int i = 0; i < 256; i++)
+ tokenTypes[i] = 0;
+ }
+
+ /**
+ * Set a boolean indicating whether or not slash slash comments should be
+ * recognized. The comment ends at a new line.
+ *
+ * @param flag
+ * <code>true</code> if <code>//</code> should be recognized
+ * as the start of a comment, <code>false</code> otherwise.
+ */
+ public void slashSlashComments(boolean flag) {
+ slashSlashComments = flag;
+ }
+
+ /**
+ * Set a boolean indicating whether or not slash star comments should be
+ * recognized. Slash-star comments cannot be nested and end when a
+ * star-slash combination is found.
+ *
+ * @param flag
+ * <code>true</code> if <code>/*</code> should be recognized
+ * as the start of a comment, <code>false</code> otherwise.
+ */
+ public void slashStarComments(boolean flag) {
+ slashStarComments = flag;
+ }
+
+ /**
+ * Answer the state of this tokenizer in a readable format.
+ *
+ * @return The current state of this tokenizer.
+ */
+ public String toString() {
+ // Values determined through experimentation
+ StringBuilder result = new StringBuilder();
+ result.append("Token["); //$NON-NLS-1$
+ switch (ttype) {
+ case TT_EOF:
+ result.append("EOF"); //$NON-NLS-1$
+ break;
+ case TT_EOL:
+ result.append("EOL"); //$NON-NLS-1$
+ break;
+ case TT_NUMBER:
+ result.append("n="); //$NON-NLS-1$
+ result.append(nval);
+ break;
+ case TT_WORD:
+ result.append(sval);
+ break;
+ default:
+ result.append('\'');
+ result.append((char) ttype);
+ result.append('\'');
+ break;
+ }
+ result.append("], line "); //$NON-NLS-1$
+ result.append(lineNumber);
+ return result.toString();
+ }
+
+ /**
+ * Set the characters ranging from <code>low</code> to <code>hi</code>
+ * to be regarded as whitespace characters.
+ *
+ * @param low
+ * The starting range for whitespace characters.
+ * @param hi
+ * The ending range for whitespace characters.
+ */
+ public void whitespaceChars(int low, int hi) {
+ if (low < 0)
+ low = 0;
+ if (hi > tokenTypes.length)
+ hi = tokenTypes.length - 1;
+ for (int i = low; i <= hi; i++)
+ tokenTypes[i] = TOKEN_WHITE;
+ }
+
+ /**
+ * Set the characters ranging from <code>low</code> to <code>hi</code>
+ * to be regarded as word characters.
+ *
+ * @param low
+ * The starting range for word characters.
+ * @param hi
+ * The ending range for word characters.
+ */
+ public void wordChars(int low, int hi) {
+ if (low < 0)
+ low = 0;
+ if (hi > tokenTypes.length)
+ hi = tokenTypes.length - 1;
+ for (int i = low; i <= hi; i++)
+ tokenTypes[i] |= TOKEN_WORD;
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StreamTokenizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringBufferInputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringBufferInputStream.java?rev=432462&r1=432461&r2=432462&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringBufferInputStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringBufferInputStream.java Thu Aug 17 18:45:35 2006
@@ -1,148 +1,148 @@
-/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package java.io;
-
-
-/**
- * StringBufferInputStream is a class for to allow a String to be used as an
- * InputStream.
- *
- * @deprecated Use StringReader
- */
-public class StringBufferInputStream extends InputStream {
- /**
- * The String containing the data to read.
- */
- protected String buffer;
-
- /**
- * The total number of characters inside the buffer.
- */
- protected int count;
-
- /**
- * The current position within the String buffer.
- */
- protected int pos;
-
- /**
- * Constructs a new StringBufferInputStream on the String <code>str</code>.
- *
- * @param str
- * the String to read characters from.
- */
- public StringBufferInputStream(String str) {
- if (str != null) {
- buffer = str;
- count = str.length();
- } else
- throw new NullPointerException();
- }
-
- /**
- * Answers an int representing then number of characters that are available
- * to read.
- *
- * @return the number of characters available.
- *
- */
- public synchronized int available() {
- return count - pos;
- }
-
- /**
- * Reads a single byte from this InputStream and returns the result as an
- * int. The low-order byte is returned or -1 of the end of stream was
- * encountered.
- *
- * @return the byte read or -1 if end of stream.
- */
- public synchronized int read() {
- return pos < count ? buffer.charAt(pos++) & 0xFF : -1;
- }
-
- /**
- * Reads at most <code>length</code> bytes from this InputStream and
- * stores them in byte array <code>b</code> starting at
- * <code>offset</code>. Answer the number of bytes actually read or -1 if
- * no bytes were read and end of stream was encountered.
- *
- * @param b
- * the byte array in which to store the read bytes.
- * @param offset
- * the offset in <code>b</code> to store the read bytes.
- * @param length
- * the maximum number of bytes to store in <code>b</code>.
- * @return the number of bytes actually read or -1 if end of stream.
- */
- public synchronized int read(byte b[], int offset, int length) {
- // According to 22.7.6 should return -1 before checking other
- // parameters.
- if (pos >= count) {
- return -1;
- }
- if (b != null) {
- // avoid int overflow
- if (0 <= offset && offset <= b.length && 0 <= length
- && length <= b.length - offset) {
- if (length == 0) {
- return 0;
- }
-
- int copylen = count - pos < length ? count - pos : length;
- for (int i = 0; i < copylen; i++)
- b[offset + i] = (byte) buffer.charAt(pos + i);
- pos += copylen;
- return copylen;
- }
- throw new ArrayIndexOutOfBoundsException();
- }
- throw new NullPointerException(org.apache.harmony.luni.util.Msg.getString("K0047")); //$NON-NLS-1$
- }
-
- /**
- * Reset this InputStream to position 0. Reads/Skips will now take place
- * from this position.
- *
- */
- public synchronized void reset() {
- pos = 0;
- }
-
- /**
- * Skips <code>count</code> number of characters in this InputStream.
- * Subsequent <code>read()</code>'s will not return these characters
- * unless <code>reset()</code> is used.
- *
- * @param n
- * the number of characters to skip.
- * @return the number of characters actually skipped.
- */
- public synchronized long skip(long n) {
- if (n <= 0)
- return 0;
-
- int numskipped;
- if (this.count - pos < n) {
- numskipped = this.count - pos;
- pos = this.count;
- } else {
- numskipped = (int) n;
- pos += n;
- }
- return numskipped;
- }
-}
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.io;
+
+
+/**
+ * StringBufferInputStream is a class for to allow a String to be used as an
+ * InputStream.
+ *
+ * @deprecated Use StringReader
+ */
+public class StringBufferInputStream extends InputStream {
+ /**
+ * The String containing the data to read.
+ */
+ protected String buffer;
+
+ /**
+ * The total number of characters inside the buffer.
+ */
+ protected int count;
+
+ /**
+ * The current position within the String buffer.
+ */
+ protected int pos;
+
+ /**
+ * Constructs a new StringBufferInputStream on the String <code>str</code>.
+ *
+ * @param str
+ * the String to read characters from.
+ */
+ public StringBufferInputStream(String str) {
+ if (str != null) {
+ buffer = str;
+ count = str.length();
+ } else
+ throw new NullPointerException();
+ }
+
+ /**
+ * Answers an int representing then number of characters that are available
+ * to read.
+ *
+ * @return the number of characters available.
+ *
+ */
+ public synchronized int available() {
+ return count - pos;
+ }
+
+ /**
+ * Reads a single byte from this InputStream and returns the result as an
+ * int. The low-order byte is returned or -1 of the end of stream was
+ * encountered.
+ *
+ * @return the byte read or -1 if end of stream.
+ */
+ public synchronized int read() {
+ return pos < count ? buffer.charAt(pos++) & 0xFF : -1;
+ }
+
+ /**
+ * Reads at most <code>length</code> bytes from this InputStream and
+ * stores them in byte array <code>b</code> starting at
+ * <code>offset</code>. Answer the number of bytes actually read or -1 if
+ * no bytes were read and end of stream was encountered.
+ *
+ * @param b
+ * the byte array in which to store the read bytes.
+ * @param offset
+ * the offset in <code>b</code> to store the read bytes.
+ * @param length
+ * the maximum number of bytes to store in <code>b</code>.
+ * @return the number of bytes actually read or -1 if end of stream.
+ */
+ public synchronized int read(byte b[], int offset, int length) {
+ // According to 22.7.6 should return -1 before checking other
+ // parameters.
+ if (pos >= count) {
+ return -1;
+ }
+ if (b != null) {
+ // avoid int overflow
+ if (0 <= offset && offset <= b.length && 0 <= length
+ && length <= b.length - offset) {
+ if (length == 0) {
+ return 0;
+ }
+
+ int copylen = count - pos < length ? count - pos : length;
+ for (int i = 0; i < copylen; i++)
+ b[offset + i] = (byte) buffer.charAt(pos + i);
+ pos += copylen;
+ return copylen;
+ }
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ throw new NullPointerException(org.apache.harmony.luni.util.Msg.getString("K0047")); //$NON-NLS-1$
+ }
+
+ /**
+ * Reset this InputStream to position 0. Reads/Skips will now take place
+ * from this position.
+ *
+ */
+ public synchronized void reset() {
+ pos = 0;
+ }
+
+ /**
+ * Skips <code>count</code> number of characters in this InputStream.
+ * Subsequent <code>read()</code>'s will not return these characters
+ * unless <code>reset()</code> is used.
+ *
+ * @param n
+ * the number of characters to skip.
+ * @return the number of characters actually skipped.
+ */
+ public synchronized long skip(long n) {
+ if (n <= 0)
+ return 0;
+
+ int numskipped;
+ if (this.count - pos < n) {
+ numskipped = this.count - pos;
+ pos = this.count;
+ } else {
+ numskipped = (int) n;
+ pos += n;
+ }
+ return numskipped;
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/StringBufferInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native