You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2005/12/01 07:04:00 UTC
svn commit: r350181 [96/198] - in
/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/
depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/
depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/
depends/oss/win.I...
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InputStreamReader.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InputStreamReader.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InputStreamReader.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InputStreamReader.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,315 @@
+/* Copyright 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.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CoderResult;
+import java.security.AccessController;
+
+import com.ibm.oti.util.PriviAction;
+
+/**
+ * InputStreamReader is class for turning a byte Stream into a character Stream.
+ * Data read from the source input stream is converted into characters by either
+ * a default or provided character converter. By default, the encoding is
+ * assumed to ISO8859_1. The InputStreamReader contains a buffer of bytes read
+ * from the source input stream and converts these into characters as needed.
+ * The buffer size is 8K.
+ *
+ *
+ * @see OutputStreamWriter
+ */
+public class InputStreamReader extends Reader {
+ private InputStream in;
+
+ private static final int BUFFER_SIZE = 8192;
+
+ CharsetDecoder decoder;
+
+ ByteBuffer bytes = ByteBuffer.allocate(BUFFER_SIZE);
+
+ CharBuffer chars = CharBuffer.allocate(BUFFER_SIZE);
+
+ /**
+ * Constructs a new InputStreamReader on the InputStream <code>in</code>.
+ * Now character reading can be filtered through this InputStreamReader.
+ * This constructor assumes the default conversion of ISO8859_1
+ * (ISO-Latin-1).
+ *
+ * @param in
+ * the InputStream to convert to characters.
+ */
+ public InputStreamReader(InputStream in) {
+ super(in);
+ this.in = in;
+ String encoding = (String) AccessController
+ .doPrivileged(new PriviAction("file.encoding", "ISO8859_1")); //$NON-NLS-1$//$NON-NLS-2$
+ decoder = Charset.forName(encoding).newDecoder();
+ chars.limit(0);
+ }
+
+ /**
+ * Constructs a new InputStreamReader on the InputStream <code>in</code>.
+ * Now character reading can be filtered through this InputStreamReader.
+ * This constructor takes a String parameter <code>enc</code> which is the
+ * name of an encoding. If the encoding cannot be found, an
+ * UnsupportedEncodingException error is thrown.
+ *
+ * @param in
+ * the InputStream to convert to characters.
+ * @param enc
+ * a String describing the character converter to use.
+ *
+ * @throws UnsupportedEncodingException
+ * if the encoding cannot be found.
+ */
+ public InputStreamReader(InputStream in, final String enc)
+ throws UnsupportedEncodingException {
+ super(in);
+ enc.length();
+ this.in = in;
+ try {
+ decoder = Charset.forName(enc).newDecoder();
+ } catch (IllegalArgumentException e) {
+ throw new UnsupportedEncodingException();
+ }
+ chars.limit(0);
+ }
+
+ /**
+ * Constructs a new InputStreamReader on the InputStream <code>in</code>
+ * and CharsetDecoder <code>dec</code>. Now character reading can be
+ * filtered through this InputStreamReader.
+ *
+ * @param in
+ * the InputStream to convert to characters
+ * @param dec
+ * a CharsetDecoder used by the character convertion
+ */
+ public InputStreamReader(InputStream in, CharsetDecoder dec) {
+ super(in);
+ dec.averageCharsPerByte();
+ this.in = in;
+ decoder = dec;
+ chars.limit(0);
+ }
+
+ /**
+ * Constructs a new InputStreamReader on the InputStream <code>in</code>
+ * and Charset <code>charset</code>. Now character reading can be
+ * filtered through this InputStreamReader.
+ *
+ * @param in
+ * the InputStream to convert to characters
+ * @param charset
+ * the Charset that specify the character converter
+ */
+ public InputStreamReader(InputStream in, Charset charset) {
+ super(in);
+ this.in = in;
+ decoder = charset.newDecoder();
+ chars.limit(0);
+ }
+
+ /**
+ * Close this InputStreamReader. This implementation closes the source
+ * InputStream and releases all local storage.
+ *
+ *
+ * @throws IOException
+ * If an error occurs attempting to close this
+ * InputStreamReader.
+ */
+ public void close() throws IOException {
+ synchronized (lock) {
+ decoder = null;
+ if (in != null) {
+ in.close();
+ in = null;
+ }
+ }
+ }
+
+ /**
+ * Answer the String which identifies the encoding used to convert bytes to
+ * characters. The value <code>null</code> is returned if this Reader has
+ * been closed.
+ *
+ * @return the String describing the converter or null if this Reader is
+ * closed.
+ */
+ public String getEncoding() {
+ return decoder.charset().name();
+ }
+
+ /**
+ * Reads a single character from this InputStreamReader 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. The byte value is either
+ * obtained from converting bytes in this readers buffer or by first filling
+ * the buffer from the source InputStream and then reading from the buffer.
+ *
+ * @return the character read or -1 if end of reader.
+ *
+ * @throws IOException
+ * If the InputStreamReader is already closed or some other IO
+ * error occurs.
+ */
+ public int read() throws IOException {
+ synchronized (lock) {
+ if (isOpen()) {
+ if (chars.limit() == chars.position()) {
+ fillBuf();
+ }
+ if (chars.limit() == 0) {
+ return -1;
+ }
+ return chars.get();
+ }
+ throw new IOException("InputStreamReader is closed."); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * 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. The bytes are either obtained from converting bytes in
+ * this readers buffer or by first filling the buffer from the source
+ * InputStream and then reading from the buffer.
+ *
+ * @param buf
+ * character array to store the read characters
+ * @param offset
+ * offset in buf to store the read characters
+ * @param length
+ * maximum number of characters to read
+ * @return the number of characters read or -1 if end of reader.
+ *
+ * @throws IOException
+ * If the InputStreamReader is already closed or some other IO
+ * error occurs.
+ */
+ public int read(char[] buf, int offset, int length) throws IOException {
+ synchronized (lock) {
+ if (isOpen()) {
+ if (length == 0)
+ return 0;
+ if (offset < 0 || length < 0 || offset + length > buf.length) {
+ throw new IndexOutOfBoundsException();
+ }
+ // read at least once
+ if (chars.limit() == chars.position()) {
+ fillBuf();
+ }
+ int position = chars.position();
+ int availableChars = chars.limit() - position;
+ // read at least once for one byte
+ int needChars = length;
+ while (availableChars < needChars) {
+ System.arraycopy(chars.array(), position, buf, offset,
+ availableChars);
+ chars.position(position + availableChars);
+ needChars -= availableChars;
+ offset += availableChars;
+ if (in.available() <= 0) {
+ return needChars == length ? -1 : length - needChars;
+ }
+ fillBuf();
+ position = chars.position();
+ availableChars = chars.limit();
+ if (availableChars == 0) {
+ return needChars == length ? -1 : length - needChars;
+ }
+ }
+ System.arraycopy(chars.array(), position, buf, offset,
+ needChars);
+ chars.position(chars.position() + needChars);
+ return length;
+ }
+ throw new IOException("InputStreamReader is closed."); //$NON-NLS-1$
+ }
+ }
+
+ /*
+ * Answer a boolean indicating whether or not this InputStreamReader is
+ * open.
+ */
+ private boolean isOpen() {
+ return in != null;
+ }
+
+ /*
+ * refill the buffer from wrapped InputStream
+ */
+ private void fillBuf() throws IOException {
+ chars.clear();
+ int read = 0;
+ try {
+ read = in.read(bytes.array());
+ } catch (IOException e) {
+ chars.limit(0);
+ throw e;
+ }
+ if (read == -1) {
+ chars.limit(0);
+ return;
+ }
+ bytes.limit(read);
+ boolean endOfInput = read < BUFFER_SIZE;
+ CoderResult result = decoder.decode(bytes, chars, endOfInput);
+ if (result.isError()) {
+ throw new IOException(result.toString());
+ }
+ bytes.clear();
+ chars.flip();
+ }
+
+ /**
+ * Answers a <code>boolean</code> indicating whether or not this
+ * InputStreamReader 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. This implementation answers
+ * <code>true</code> if there are bytes available in the buffer or the
+ * source InputStream has bytes available.
+ *
+ * @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 InputStreamReader is already closed or some other IO
+ * error occurs.
+ */
+ public boolean ready() throws IOException {
+ synchronized (lock) {
+ if (in == null) {
+ throw new IOException("This reader has been closed!"); //$NON-NLS-1$
+ }
+ try {
+ return chars.limit() > chars.position() || in.available() > 0;
+ } catch (IOException e) {
+ return false;
+ }
+
+ }
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InterruptedIOException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InterruptedIOException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InterruptedIOException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InterruptedIOException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,53 @@
+/* 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;
+
+
+/**
+ * This IO exception is thrown when a program reading or writing to a stream is
+ * interrupted. This is also thrown when a socket timeout occurs before the
+ * request has completed.
+ *
+ */
+public class InterruptedIOException extends IOException {
+
+ /**
+ * The number of bytes transferred before the IO interrupt occurred. The
+ * default is 0 but the value may be filled in by the caller of the
+ * constructor.
+ */
+ public int bytesTransferred;
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ *
+ */
+ public InterruptedIOException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * The detail message for the exception.
+ */
+ public InterruptedIOException(String detailMessage) {
+ super(detailMessage);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InvalidClassException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InvalidClassException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InvalidClassException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InvalidClassException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,85 @@
+/* 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;
+
+
+/**
+ * A problem was found with the class of one of the objects being serialized or
+ * deserialized. These can be
+ * <ul>
+ * <li>The SUIDs of the class loaded by the VM and the serialized class info do
+ * not match</li>
+ * <li>A serializable or externalizable object cannot be instantiated (when
+ * deserializing) because the empty constructor that needs to be run is not
+ * visible or fails.</li>
+ * </ul>
+ *
+ * @see ObjectInputStream #readObject()
+ * @see ObjectInputValidation#validateObject()
+ */
+public class InvalidClassException extends ObjectStreamException {
+
+ static final long serialVersionUID = -4333316296251054416L;
+
+ /**
+ * The fully qualified name of the class that caused the problem
+ */
+ public String classname;
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * The detail message for the exception.
+ */
+ public InvalidClassException(String detailMessage) {
+ super(detailMessage);
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback, message and
+ * the fully qualified name of the class which caused the exception filled
+ * in.
+ *
+ * @param className
+ * The detail message for the exception.
+ * @param detailMessage
+ * The detail message for the exception.
+ */
+ public InvalidClassException(String className, String detailMessage) {
+ super(detailMessage);
+ this.classname = className;
+ }
+
+ /**
+ * Answers the extra information message which was provided when the
+ * exception was created. If no message was provided at creation time, then
+ * answer null. If a message was provided and a class name which caused the
+ * exception, the values are concatenated and returned.
+ *
+ * @return The receiver's message, possibly concatenated with the name of
+ * the class that caused the problem.
+ */
+ public String getMessage() {
+ String msg = super.getMessage();
+ if (classname != null) {
+ msg = classname + ';' + ' ' + msg;
+ }
+ return msg;
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InvalidObjectException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InvalidObjectException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InvalidObjectException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/InvalidObjectException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,42 @@
+/* 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;
+
+
+/**
+ * The object graph loaded (deserialized) can be validated by a collection of
+ * validator objects. If these decide the validation fails, then will throw
+ * InvalidObjectException.
+ *
+ * @see ObjectInputStream#registerValidation(ObjectInputValidation, int)
+ * @see ObjectInputValidation#validateObject()
+ */
+public class InvalidObjectException extends ObjectStreamException {
+
+ static final long serialVersionUID = 3233174318281839583L;
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * The detail message for the exception.
+ */
+ public InvalidObjectException(String detailMessage) {
+ super(detailMessage);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/LineNumberInputStream.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/LineNumberInputStream.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/LineNumberInputStream.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/LineNumberInputStream.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,231 @@
+/* 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;
+
+
+/**
+ * LineNumberInputStream is a filter class which counts the number of line
+ * terminators from the data read from the target InputStream. A line delimeter
+ * sequence is determined by '\r', '\n', or '\r\n'. When using <code>read</code>,
+ * the sequence is always translated into '\n'.
+ *
+ * @deprecated Use LineNumberReader
+ */
+public class LineNumberInputStream extends FilterInputStream {
+ private int lineNumber = 0;
+
+ private int markedLineNumber = -1;
+
+ private int lastChar = -1, markedLastChar;
+
+ /**
+ * Constructs a new LineNumberInputStream on the InputStream <code>in</code>.
+ * All reads are now filtered through this stream and line numbers will be
+ * counted for all data read from this Stream.
+ *
+ * @param in
+ * The non-null InputStream to count line numbers.
+ */
+ public LineNumberInputStream(InputStream in) {
+ super(in);
+ }
+
+ /**
+ * Answers a int representing the number of bytes that are available before
+ * this LineNumberInputStream will block. This method returns the number of
+ * bytes available in the target stream. Since the target input stream may
+ * just be a sequence of <code>\r\n</code> characters and this filter only
+ * returns <code>\n<code> then <code>available</code> can only
+ * guarantee <code>target.available()/2</code> characters.
+ *
+ * @return int the number of bytes available before blocking.
+ *
+ * @throws IOException If an error occurs in this stream.
+ */
+ public int available() throws IOException {
+ return in.available() / 2 + (lastChar == -1 ? 0 : 1);
+ }
+
+ /**
+ * Answers a int representing the current line number for this
+ * LineNumberInputStream.
+ *
+ * @return int the current line number.
+ */
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ /**
+ * Set a Mark position in this LineNumberInputStream. The parameter
+ * <code>readLimit</code> indicates how many bytes can be read before a
+ * mark is invalidated. Sending reset() will reposition the Stream back to
+ * the marked position provided <code>readLimit</code> has not been
+ * surpassed. The lineNumber count will also be reset to the last marked
+ * lineNumber count.
+ * <p>
+ * This implementation sets a mark in the target stream.
+ *
+ * @param readlimit
+ * The number of bytes to be able to read before invalidating the
+ * mark.
+ */
+ public void mark(int readlimit) {
+ in.mark(readlimit);
+ markedLineNumber = lineNumber;
+ markedLastChar = lastChar;
+ }
+
+ /**
+ * Reads a single byte from this LineNumberInputStream and returns the
+ * result as an int. The low-order byte is returned or -1 of the end of
+ * stream was encountered. This implementation returns a byte from the
+ * target stream. The line number count is incremented if a line terminator
+ * is encountered. A line delimeter sequence is determined by '\r', '\n', or
+ * '\r\n'. In this method, the sequence is always translated into '\n'.
+ *
+ * @return int The byte read or -1 if end of stream.
+ *
+ * @throws IOException
+ * If the stream is already closed or another IOException
+ * occurs.
+ */
+ public int read() throws IOException {
+ int currentChar = lastChar;
+ if (currentChar == -1)
+ currentChar = in.read();
+ else
+ lastChar = -1;
+ switch (currentChar) {
+ case '\r':
+ currentChar = '\n';
+ lastChar = in.read();
+ if (lastChar == '\n')
+ lastChar = -1;
+ case '\n':
+ lineNumber++;
+ }
+ return currentChar;
+ }
+
+ /**
+ * Reads at most <code>length</code> bytes from this LineNumberInputStream
+ * 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. This implementation
+ * reads bytes from the target stream. The line number count is incremented
+ * if a line terminator is encountered. A line delimeter sequence is
+ * determined by '\r', '\n', or '\r\n'. In this method, the sequence is
+ * always translated into '\n'.
+ *
+ * @param buffer
+ * the non-null byte array in which to store the read bytes.
+ * @param offset
+ * the offset in <code>buffer</code> to store the read bytes.
+ * @param length
+ * 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 the stream is already closed or another IOException
+ * occurs.
+ * @throws NullPointerException
+ * If <code>buffer</code> is <code>null</code>.
+ * @throws IllegalArgumentException
+ * If <code>offset</code> or <code>count</code> are out of
+ * bounds.
+ */
+ public int read(byte[] buffer, int offset, int length) throws IOException {
+ if (buffer != null) {
+ // avoid int overflow
+ if (0 <= offset && offset <= buffer.length && 0 <= length
+ && length <= buffer.length - offset) {
+ for (int i = 0; i < length; i++) {
+ int currentChar;
+ try {
+ currentChar = read();
+ } catch (IOException e) {
+ if (i != 0)
+ return i;
+ throw e;
+ }
+ if (currentChar == -1)
+ return i == 0 ? -1 : i;
+ buffer[offset + i] = (byte) currentChar;
+ }
+ return length;
+ }
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ throw new NullPointerException();
+ }
+
+ /**
+ * Reset this LineNumberInputStream to the last marked location. If the
+ * <code>readlimit</code> has been passed or no <code>mark</code> has
+ * been set, throw IOException. This implementation resets the target
+ * stream. It also resets the line count to what is was when this Stream was
+ * marked.
+ *
+ * @throws IOException
+ * If the stream is already closed or another IOException
+ * occurs.
+ */
+ public void reset() throws IOException {
+ in.reset();
+ lineNumber = markedLineNumber;
+ lastChar = markedLastChar;
+ }
+
+ /**
+ * Sets the lineNumber of this LineNumberInputStream to the specified
+ * <code>lineNumber</code>. Note that this may have side effects on the
+ * line number associated with the last marked position.
+ *
+ * @param lineNumber
+ * the new lineNumber value.
+ */
+ public void setLineNumber(int lineNumber) {
+ this.lineNumber = lineNumber;
+ }
+
+ /**
+ * Skips <code>count</code> number of bytes in this InputStream.
+ * Subsequent <code>read()</code>'s will not return these bytes unless
+ * <code>reset()</code> is used. This implementation skips
+ * <code>count</code> number of bytes in the target stream and increments
+ * the lineNumber count as bytes are skipped.
+ *
+ * @param count
+ * the number of bytes to skip.
+ * @return the number of bytes actually skipped.
+ *
+ * @throws IOException
+ * If the stream is already closed or another IOException
+ * occurs.
+ */
+ public long skip(long count) throws IOException {
+ if (count <= 0)
+ return 0;
+ for (int i = 0; i < count; i++) {
+ int currentChar = read();
+ if (currentChar == -1)
+ return i;
+ }
+ return count;
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/LineNumberReader.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/LineNumberReader.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/LineNumberReader.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/LineNumberReader.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,259 @@
+/* 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;
+
+
+/**
+ * LineNumberReader is a buffered character input reader which counts line
+ * numbers as data is being read. The line number starts at 0 and is incremented
+ * any time '\r', '\n', or '\r\n' is read.
+ *
+ * @see BufferedWriter
+ */
+public class LineNumberReader extends BufferedReader {
+ private int lineNumber = 0;
+
+ private int markedLineNumber = -1;
+
+ private boolean lastWasCR = false, markedLastWasCR;
+
+ /**
+ * Constructs a new buffered LineNumberReader on the Reader <code>in</code>.
+ * The default buffer size (8K) is allocated and all reads can now be
+ * filtered through this LineNumberReader.
+ *
+ * @param in
+ * the Reader to buffer reads on.
+ */
+ public LineNumberReader(Reader in) {
+ super(in);
+ }
+
+ /**
+ * Constructs a new buffered LineNumberReader on the Reader <code>in</code>.
+ * The buffer size is specified by the parameter <code>size</code> and all
+ * reads can now be filtered through this LineNumberReader.
+ *
+ * @param in
+ * the Reader to buffer reads on.
+ * @param size
+ * the size of buffer to allocate.
+ */
+ public LineNumberReader(Reader in, int size) {
+ super(in, size);
+ }
+
+ /**
+ * Answers a int representing the current line number for this
+ * LineNumberReader.
+ *
+ * @return int the current line number.
+ */
+ public int getLineNumber() {
+ synchronized (lock) {
+ return lineNumber;
+ }
+ }
+
+ /**
+ * Set a Mark position in this LineNumberReader. 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. The lineNumber associated with this marked position will also
+ * be saved and restored when reset() is sent provided
+ * <code>readLimit</code> has not been surpassed.
+ *
+ * @param readlimit
+ * an int representing how many characters must be read before
+ * invalidating the mark.
+ *
+ * @throws IOException
+ * If an error occurs attempting mark this LineNumberReader.
+ */
+ public void mark(int readlimit) throws IOException {
+ synchronized (lock) {
+ super.mark(readlimit);
+ markedLineNumber = lineNumber;
+ markedLastWasCR = lastWasCR;
+ }
+ }
+
+ /**
+ * Reads a single char from this LineNumberReader and returns the result as
+ * an int. The low-order 2 bytes are returned or -1 of the end of reader was
+ * encountered. This implementation returns a char from the target reader.
+ * The line number count is incremented if a line terminator is encountered.
+ * A line delimeter sequence is determined by '\r', '\n', or '\r\n'. In this
+ * method, the sequence is always translated into '\n'.
+ *
+ * @return int The char read or -1 if end of reader.
+ *
+ * @throws IOException
+ * If the reader is already closed or another IOException
+ * occurs.
+ */
+ public int read() throws IOException {
+ synchronized (lock) {
+ int ch = super.read();
+ if (ch == '\n' && lastWasCR)
+ ch = super.read();
+ lastWasCR = false;
+ switch (ch) {
+ case '\r':
+ ch = '\n';
+ lastWasCR = true;
+ // fall through
+ case '\n':
+ lineNumber++;
+ }
+ return ch;
+ }
+ }
+
+ /**
+ * Reads at most <code>count</code> chars from this LineNumberReader and
+ * stores them in char array <code>buffer</code> starting at offset
+ * <code>offset</code>. Answer the number of chars actually read or -1 if
+ * no chars were read and end of reader was encountered. This implementation
+ * reads chars from the target stream. The line number count is incremented
+ * if a line terminator is encountered. A line delimeter sequence is
+ * determined by '\r', '\n', or '\r\n'. In this method, the sequence is
+ * always translated into '\n'.
+ *
+ * @param buffer
+ * the char array in which to store the read chars.
+ * @param offset
+ * the offset in <code>buffer</code> to store the read chars.
+ * @param count
+ * the maximum number of chars to store in <code>buffer</code>.
+ * @return the number of chars actually read or -1 if end of reader.
+ *
+ * @throws IOException
+ * If the reader is already closed or another IOException
+ * occurs.
+ */
+
+ public int read(char[] buffer, int offset, int count) throws IOException {
+ synchronized (lock) {
+ int read = super.read(buffer, offset, count);
+ if (read == -1)
+ return -1;
+ for (int i = 0; i < read; i++) {
+ char ch = buffer[offset + i];
+ if (ch == '\r') {
+ lineNumber++;
+ lastWasCR = true;
+ } else if (ch == '\n') {
+ if (!lastWasCR)
+ lineNumber++;
+ lastWasCR = false;
+ } else
+ lastWasCR = false;
+ }
+ return read;
+ }
+ }
+
+ /**
+ * Answers a <code>String</code> representing the next line of text
+ * available in this LineNumberReader. A line is represented by 0 or more
+ * characters followed by <code>'\n'</code>, <code>'\r'</code>,
+ * <code>"\n\r"</code> or end of stream. The <code>String</code> does
+ * not include the newline sequence.
+ *
+ * @return String the contents of the line or null if no characters were
+ * read before end of stream.
+ *
+ * @throws IOException
+ * If the LineNumberReader is already closed or some other IO
+ * error occurs.
+ */
+ public String readLine() throws IOException {
+ synchronized (lock) {
+ /* Typical Line Length */
+ StringBuffer result = new StringBuffer(80);
+ while (true) {
+ int character = read();
+ if (character == -1)
+ return result.length() != 0 ? result.toString() : null;
+ if (character == '\n')
+ return result.toString();
+ result.append((char) character);
+ }
+ }
+ }
+
+ /**
+ * Reset this LineNumberReader to the last marked location. If the
+ * <code>readlimit</code> has been passed or no <code>mark</code> has
+ * been set, throw IOException. This implementation resets the target
+ * reader. It also resets the line count to what is was when this reader was
+ * marked.
+ *
+ * @throws IOException
+ * If the reader is already closed or another IOException
+ * occurs.
+ */
+ public void reset() throws IOException {
+ synchronized (lock) {
+ super.reset();
+ lineNumber = markedLineNumber;
+ lastWasCR = markedLastWasCR;
+ }
+ }
+
+ /**
+ * Sets the lineNumber of this LineNumberReader to the specified
+ * <code>lineNumber</code>. Note that this may have side effects on the
+ * line number associated with the last marked position.
+ *
+ * @param lineNumber
+ * the new lineNumber value.
+ */
+ public void setLineNumber(int lineNumber) {
+ synchronized (lock) {
+ this.lineNumber = lineNumber;
+ }
+ }
+
+ /**
+ * Skips <code>count</code> number of chars in this LineNumberReader.
+ * Subsequent <code>read()</code>'s will not return these chars unless
+ * <code>reset()</code> is used. This implementation skips
+ * <code>count</code> number of chars in the target stream and increments
+ * the lineNumber count as chars are skipped.
+ *
+ * @param count
+ * the number of chars to skip.
+ * @return the number of chars actually skipped.
+ *
+ * @throws IOException
+ * If the reader is already closed or another IOException
+ * occurs.
+ */
+ public long skip(long count) throws IOException {
+ if (count >= 0) {
+ synchronized (lock) {
+ for (int i = 0; i < count; i++)
+ if (read() == -1)
+ return i;
+ return count;
+ }
+ }
+ throw new IllegalArgumentException();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/NotActiveException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/NotActiveException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/NotActiveException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/NotActiveException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,56 @@
+/* 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;
+
+
+/**
+ * Some methods in ObjectInputStream and ObjectOutputStream can only be called
+ * from a nested call to readObject() or writeObject(). Any attempt to call them
+ * from another context will cause this exception to be thrown. The list of
+ * methods that are protected this way is:
+ * <ul>
+ * <li>ObjectInputStream.defaultReadObject()</li>
+ * <li>ObjectInputStream.registerValidation()</li>
+ * <li>ObjectOutputStream.defaultWriteObject()</li>
+ * </ul>
+ *
+ * @see ObjectInputStream#defaultReadObject()
+ * @see ObjectInputStream#registerValidation(ObjectInputValidation, int)
+ * @see ObjectOutputStream#defaultWriteObject()
+ */
+public class NotActiveException extends ObjectStreamException {
+
+ static final long serialVersionUID = -3893467273049808895L;
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ */
+ public NotActiveException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * The detail message for the exception.
+ */
+ public NotActiveException(String detailMessage) {
+ super(detailMessage);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/NotSerializableException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/NotSerializableException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/NotSerializableException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/NotSerializableException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,53 @@
+/* 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 an implementation of ObjectOutput.writeObject() is passed an object that
+ * is not serializable, it will throw this type of exception. This can happen if
+ * the object does not implement Serializable or Externalizable, or if it is
+ * Serializable but it overrides writeObject(ObjectOutputStream) and explicitely
+ * decides it wants to prevent serialization, by throwing this type of
+ * exception.
+ *
+ * @see ObjectOutputStream#writeObject(Object)
+ * @see ObjectOutput#writeObject(Object)
+ */
+public class NotSerializableException extends ObjectStreamException {
+
+ static final long serialVersionUID = 2906642554793891381L;
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ *
+ */
+ public NotSerializableException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * The detail message for the exception.
+ */
+ public NotSerializableException(String detailMessage) {
+ super(detailMessage);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/ObjectInput.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/ObjectInput.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/ObjectInput.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/ObjectInput.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,120 @@
+/* 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;
+
+
+/**
+ * Streams to be used with serialization to read objects must implement this
+ * interface. ObjectInputStream is one example.
+ *
+ * @see ObjectInputStream
+ * @see ObjectOutput
+ */
+public interface ObjectInput extends DataInput {
+ /**
+ * Answers a int representing then number of bytes of primitive data that
+ * are available.
+ *
+ * @return int the number of primitive bytes available.
+ *
+ * @throws IOException
+ * If an error occurs in this ObjectInput.
+ */
+ public int available() throws IOException;
+
+ /**
+ * Close this ObjectInput. Concrete implementations of this class should
+ * free any resources during close.
+ *
+ * @throws IOException
+ * If an error occurs attempting to close this ObjectInput.
+ */
+ public void close() throws IOException;
+
+ /**
+ * Reads a single byte from this ObjectInput and returns the result as an
+ * int. The low-order byte is returned or -1 of the end of stream was
+ * encountered.
+ *
+ * @return int The byte read or -1 if end of ObjectInput.
+ *
+ * @throws IOException
+ * If the ObjectInput is already closed or another IOException
+ * occurs.
+ */
+ public int read() throws IOException;
+
+ /**
+ * Reads bytes from the <code>ObjectInput</code> and stores them in byte
+ * array <code>buffer</code>. Blocks while waiting for input.
+ *
+ * @param buffer
+ * the array in which to store the read bytes.
+ * @return how many bytes were read or <code>-1</code> if encountered end
+ * of <code>ObjectInput</code>.
+ *
+ * @throws IOException
+ * If the <code>ObjectInput</code> is already closed or
+ * another IOException occurs.
+ */
+ public int read(byte[] buffer) throws IOException;
+
+ /**
+ * Reads at most <code>count</code> bytes from the ObjectInput and stores
+ * them in byte array <code>buffer</code> starting at offset
+ * <code>count</code>. Answer the number of bytes actually read or -1 if
+ * no bytes were read and end of ObjectInput 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 ObjectInput.
+ *
+ * @throws IOException
+ * If the ObjectInput is already closed or another IOException
+ * occurs.
+ */
+ public int read(byte[] buffer, int offset, int count) throws IOException;
+
+ /**
+ * Reads the next object from this ObjectInput.
+ *
+ * @return the next object read from this ObjectInput
+ *
+ * @throws IOException
+ * If an error occurs attempting to read from this ObjectInput.
+ * @throws ClassNotFoundException
+ * If the object's class cannot be found
+ */
+ public Object readObject() throws ClassNotFoundException, IOException;
+
+ /**
+ * Skips <code>toSkip</code> number of bytes in this ObjectInput.
+ * Subsequent <code>read()</code>'s will not return these bytes.
+ *
+ * @param toSkip
+ * the number of bytes to skip.
+ * @return the number of bytes actually skipped.
+ *
+ * @throws IOException
+ * If the ObjectInput is already closed or another IOException
+ * occurs.
+ */
+ public long skip(long toSkip) throws IOException;
+}