harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r350181 [101/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....
Date Thu, 01 Dec 2005 06:04:00 GMT
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/RandomAccessFile.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/RandomAccessFile.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/RandomAccessFile.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/RandomAccessFile.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,951 @@
+/* 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.nio.channels.FileChannel;
+
+/**
+ * RandomAccessFile is a class which allows positioning of the next read
+ * anywhere in the file. This is useful for reading specific locations of files
+ * or following links within a file. Most input classes only support forward
+ * skipping.
+ * 
+ */
+
+public class RandomAccessFile implements DataInput, DataOutput {
+	/**
+	 * The FileDescriptor representing this RandomAccessFile.
+	 */
+	FileDescriptor fd;
+
+	// The unique file channel associated with this FileInputStream (lazily
+	// initialized).
+	private FileChannel channel;
+
+	private boolean isReadOnly;
+
+	// Fill in the JNI id caches
+	private static native void oneTimeInitialization();
+
+	static {
+		oneTimeInitialization();
+	}
+
+	/**
+	 * Constructs a new RandomAccessFile on the File <code>file</code> and
+	 * opens it according to the access String in <code>mode</code>. The
+	 * access mode may be one of <code>"r"</code> for read access only, or
+	 * <code>"rw"</code> for read/write access.
+	 * 
+	 * @param file
+	 *            the File to open.
+	 * @param mode
+	 *            "r" for read only, or "rw" for read/write.
+	 * 
+	 * @throws FileNotFoundException
+	 *             If the <code>mode</code> is incorrect or the File cannot be
+	 *             opened in the requested <code>mode</code>.
+	 * 
+	 * @see java.lang.SecurityManager#checkRead(FileDescriptor)
+	 * @see java.lang.SecurityManager#checkWrite(FileDescriptor)
+	 */
+	public RandomAccessFile(File file, String mode)
+			throws FileNotFoundException {
+		super();
+		if (mode.equals("r") || mode.equals("rw")) { //$NON-NLS-1$ //$NON-NLS-2$
+			SecurityManager security = System.getSecurityManager();
+			if (security != null) {
+				security.checkRead(file.getPath());
+				if (mode.equals("rw")) //$NON-NLS-1$
+					security.checkWrite(file.getPath());
+			}
+			fd = new FileDescriptor();
+			if (openImpl(file.properPath(true), mode.equals("rw")) != 0) //$NON-NLS-1$
+				throw new FileNotFoundException(file.getPath());
+
+			isReadOnly = mode.equals("r"); //$NON-NLS-1$
+
+		} else
+			throw new IllegalArgumentException(com.ibm.oti.util.Msg
+					.getString("K0081")); //$NON-NLS-1$
+	}
+
+	/**
+	 * Constructs a new RandomAccessFile on the file named <code>fileName</code>
+	 * and opens it according to the access String in <code>mode</code>. The
+	 * file may be absolute or relative to the System property
+	 * <code>"user.dir"</code>. The access mode may be one of
+	 * <code>"r"</code> for read access only, or <code>"rw"</code> for
+	 * read/write access.
+	 * 
+	 * 
+	 * @param fileName
+	 *            the filename of the file to open.
+	 * @param mode
+	 *            "r" for read only, or "rw" for read/write.
+	 * 
+	 * @throws FileNotFoundException
+	 *             If the <code>mode</code> is incorrect or the file cannot be
+	 *             opened in the requested <code>mode</code>.
+	 * 
+	 * @see java.lang.SecurityManager#checkRead(FileDescriptor)
+	 * @see java.lang.SecurityManager#checkWrite(FileDescriptor)
+	 */
+	public RandomAccessFile(String fileName, String mode)
+			throws FileNotFoundException {
+		super();
+		if (mode.equals("r") || mode.equals("rw")) {  //$NON-NLS-1$//$NON-NLS-2$
+			SecurityManager security = System.getSecurityManager();
+			if (security != null) {
+				security.checkRead(fileName);
+				if (mode.equals("rw")) //$NON-NLS-1$
+					security.checkWrite(fileName);
+			}
+			fd = new FileDescriptor();
+			File f = new File(fileName);
+			if (openImpl(f.properPath(true), mode.equals("rw")) != 0) //$NON-NLS-1$
+				throw new FileNotFoundException(fileName);
+
+		} else
+			throw new IllegalArgumentException(com.ibm.oti.util.Msg
+					.getString("K0081")); //$NON-NLS-1$
+	}
+
+	/**
+	 * Close this RandomAccessFile.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to close this RandomAccessFile.
+	 */
+	public void close() throws IOException {
+		closeImpl();
+	}
+
+	private native void closeImpl() throws IOException;
+
+	/**
+	 * Answers the FileChannel equivalent to this stream.
+	 * <p>
+	 * The file channel is write-only and has an initial position within the
+	 * file that is the same as the current position of this FileOutputStream
+	 * within the file. All changes made to the underlying file descriptor state
+	 * via the channel are visible by the output stream and vice versa.
+	 * </p>
+	 * 
+	 * @return the file channel representation for this FileOutputStream.
+	 */
+	public final synchronized FileChannel getChannel() {
+		if (channel == null) {
+			channel = FileChannelFactory.getFileChannel(fd.descriptor,
+					(isReadOnly ? FileChannelFactory.O_RDONLY
+							: FileChannelFactory.O_RDWR));
+		}
+		return channel;
+	}
+
+	/**
+	 * Answers the FileDescriptor representing the operating system resource for
+	 * this RandomAccessFile.
+	 * 
+	 * @return the FileDescriptor for this RandomAccessFile.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to get the FileDescriptor of
+	 *             this RandomAccessFile.
+	 */
+	public final FileDescriptor getFD() throws IOException {
+		return fd;
+	}
+
+	/**
+	 * Answers the current position within this RandomAccessFile. All reads and
+	 * writes take place at the current file pointer position.
+	 * 
+	 * @return the current file pointer position.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to get the file pointer
+	 *             position of this RandomAccessFile.
+	 */
+	public native long getFilePointer() throws IOException;
+
+	/**
+	 * Answers the current length of this RandomAccessFile in bytes.
+	 * 
+	 * @return the current file length in bytes.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to get the file length of this
+	 *             RandomAccessFile.
+	 */
+	public native long length() throws IOException;
+
+	private native int openImpl(byte[] fileName, boolean writable);
+
+	/**
+	 * Reads a single byte from this RandomAccessFile and returns the result as
+	 * an int. The low-order byte is returned or -1 of the end of file was
+	 * encountered.
+	 * 
+	 * @return the byte read or -1 if end of file.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to read from this
+	 *             RandomAccessFile.
+	 * 
+	 * @see #write(byte[])
+	 * @see #write(byte[], int, int)
+	 * @see #write(int)
+	 */
+	public int read() throws IOException {
+		if (fd != null)
+			return readByteImpl(fd.descriptor);
+		throw new IOException();
+	}
+
+	private native int readByteImpl(long descriptor) throws IOException;
+
+	/**
+	 * Reads bytes from this RandomAccessFile into the byte array
+	 * <code>buffer</code>. The number of bytes actually read is returned.
+	 * 
+	 * @param buffer
+	 *            the buffer to read bytes into
+	 * @return the number of bytes actually read or -1 if end of file.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to read from this
+	 *             RandomAccessFile.
+	 * 
+	 * @see #write(byte[])
+	 * @see #write(byte[], int, int)
+	 * @see #write(int)
+	 */
+	public int read(byte[] buffer) throws IOException {
+		return read(buffer, 0, buffer.length);
+	}
+
+	/**
+	 * Reads at most <code>count</code> bytes from this RandomAccessFile 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 file 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 file.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to read from this
+	 *             RandomAccessFile.
+	 * 
+	 * @see #write(byte[])
+	 * @see #write(byte[], int, int)
+	 * @see #write(int)
+	 */
+	public int read(byte[] buffer, int offset, int count) throws IOException {
+		if (fd != null)
+			return readImpl(buffer, offset, count, fd.descriptor);
+		throw new IOException();
+	}
+
+	private native int readImpl(byte[] buffer, int offset, int count,
+			long descriptor) throws IOException;
+
+	/**
+	 * Reads a boolean from this stream.
+	 * 
+	 * @return boolean the next boolean value from the source stream.
+	 * 
+	 * @throws IOException
+	 *             If a problem occurs reading from this DataInputStream.
+	 * 
+	 * @see DataOutput#writeBoolean(boolean)
+	 */
+	public final boolean readBoolean() throws IOException {
+		int temp = this.read();
+		if (temp >= 0)
+			return temp != 0;
+		throw new EOFException();
+	}
+
+	/**
+	 * Reads an 8-bit byte value from this stream.
+	 * 
+	 * @return byte the next byte value from the source stream.
+	 * 
+	 * @throws IOException
+	 *             If a problem occurs reading from this DataInputStream.
+	 * 
+	 * @see DataOutput#writeByte(int)
+	 */
+	public final byte readByte() throws IOException {
+		int temp = this.read();
+		if (temp >= 0)
+			return (byte) temp;
+		throw new EOFException();
+	}
+
+	/**
+	 * Reads a 16-bit character value from this stream.
+	 * 
+	 * @return char the next <code>char</code> value from the source stream.
+	 * 
+	 * @throws IOException
+	 *             If a problem occurs reading from this DataInputStream.
+	 * 
+	 * @see DataOutput#writeChar(int)
+	 */
+	public final char readChar() throws IOException {
+		byte[] buffer = new byte[2];
+		if (read(buffer, 0, buffer.length) == buffer.length)
+			return (char) (((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff));
+		throw new EOFException();
+	}
+
+	/**
+	 * Reads a 64-bit <code>double</code> value from this stream.
+	 * 
+	 * @return double the next <code>double</code> value from the source
+	 *         stream.
+	 * 
+	 * @throws IOException
+	 *             If a problem occurs reading from this DataInputStream.
+	 * 
+	 * @see DataOutput#writeDouble(double)
+	 */
+	public final double readDouble() throws IOException {
+		return Double.longBitsToDouble(readLong());
+	}
+
+	/**
+	 * Reads a 32-bit <code>float</code> value from this stream.
+	 * 
+	 * @return float the next <code>float</code> value from the source stream.
+	 * 
+	 * @throws IOException
+	 *             If a problem occurs reading from this DataInputStream.
+	 * 
+	 * @see DataOutput#writeFloat(float)
+	 */
+	public final float readFloat() throws IOException {
+		return Float.intBitsToFloat(readInt());
+	}
+
+	/**
+	 * Reads bytes from this stream into the byte array <code>buffer</code>.
+	 * This method will block until <code>buffer.length</code> number of bytes
+	 * have been read.
+	 * 
+	 * @param buffer
+	 *            the buffer to read bytes into
+	 * 
+	 * @throws IOException
+	 *             If a problem occurs reading from this DataInputStream.
+	 * 
+	 * @see DataOutput#write(byte[])
+	 * @see DataOutput#write(byte[], int, int)
+	 */
+	public final void readFully(byte[] buffer) throws IOException {
+		readFully(buffer, 0, buffer.length);
+	}
+
+	/**
+	 * Read bytes from this stream and stores them in byte array
+	 * <code>buffer</code> starting at offset <code>offset</code>. This
+	 * method blocks until <code>count</code> number of bytes have been read.
+	 * 
+	 * @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>.
+	 * 
+	 * @throws IOException
+	 *             If a problem occurs reading from this DataInputStream.
+	 * 
+	 * @see DataOutput#write(byte[])
+	 * @see DataOutput#write(byte[], int, int)
+	 */
+	public final void readFully(byte[] buffer, int offset, int count)
+			throws IOException {
+		if (buffer != null) {
+			// avoid int overflow
+			if (0 <= offset && offset <= buffer.length && 0 <= count
+					&& count <= buffer.length - offset) {
+				while (count > 0) {
+					int result = read(buffer, offset, count);
+					if (result >= 0) {
+						offset += result;
+						count -= result;
+					} else
+						throw new EOFException();
+				}
+			} else
+				throw new IndexOutOfBoundsException();
+		} else
+			throw new NullPointerException(com.ibm.oti.util.Msg
+					.getString("K0047")); //$NON-NLS-1$
+	}
+
+	/**
+	 * Reads a 32-bit integer value from this stream.
+	 * 
+	 * @return int the next <code>int</code> value from the source stream.
+	 * 
+	 * @throws IOException
+	 *             If a problem occurs reading from this DataInputStream.
+	 * 
+	 * @see DataOutput#writeInt(int)
+	 */
+	public final int readInt() throws IOException {
+		byte[] buffer = new byte[4];
+		if (read(buffer, 0, buffer.length) == buffer.length)
+			return ((buffer[0] & 0xff) << 24) + ((buffer[1] & 0xff) << 16)
+					+ ((buffer[2] & 0xff) << 8) + (buffer[3] & 0xff);
+		throw new EOFException();
+	}
+
+	/**
+	 * Answers a <code>String</code> representing the next line of text
+	 * available in this BufferedReader. 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 BufferedReader is already closed or some other IO
+	 *             error occurs.
+	 */
+	public final String readLine() throws IOException {
+		StringBuffer line = new StringBuffer(80); // Typical line length
+		boolean foundTerminator = false;
+		long unreadPosition = 0;
+		while (true) {
+			int nextByte = read();
+			switch (nextByte) {
+			case -1:
+				return line.length() != 0 ? line.toString() : null;
+			case (byte) '\r':
+				if (foundTerminator) {
+					seek(unreadPosition);
+					return line.toString();
+				}
+				foundTerminator = true;
+				/* Have to be able to peek ahead one byte */
+				unreadPosition = getFilePointer();
+				break;
+			case (byte) '\n':
+				return line.toString();
+			default:
+				if (foundTerminator) {
+					seek(unreadPosition);
+					return line.toString();
+				}
+				line.append((char) nextByte);
+			}
+		}
+	}
+
+	/**
+	 * Reads a 64-bit <code>long</code> value from this stream.
+	 * 
+	 * @return long the next <code>long</code> value from the source stream.
+	 * 
+	 * @throws IOException
+	 *             If a problem occurs reading from this DataInputStream.
+	 * 
+	 * @see DataOutput#writeLong(long)
+	 */
+	public final long readLong() throws IOException {
+		byte[] buffer = new byte[8];
+		if (read(buffer, 0, buffer.length) == buffer.length)
+			return ((long) (((buffer[0] & 0xff) << 24)
+					+ ((buffer[1] & 0xff) << 16) + ((buffer[2] & 0xff) << 8) + (buffer[3] & 0xff)) << 32)
+					+ ((long) (buffer[4] & 0xff) << 24)
+					+ ((buffer[5] & 0xff) << 16)
+					+ ((buffer[6] & 0xff) << 8)
+					+ (buffer[7] & 0xff);
+		throw new EOFException();
+	}
+
+	/**
+	 * Reads a 16-bit <code>short</code> value from this stream.
+	 * 
+	 * @return short the next <code>short</code> value from the source stream.
+	 * 
+	 * @throws IOException
+	 *             If a problem occurs reading from this DataInputStream.
+	 * 
+	 * @see DataOutput#writeShort(int)
+	 */
+	public final short readShort() throws IOException {
+		byte[] buffer = new byte[2];
+		if (read(buffer, 0, buffer.length) == buffer.length)
+			return (short) (((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff));
+		throw new EOFException();
+	}
+
+	/**
+	 * Reads an unsigned 8-bit <code>byte</code> value from this stream and
+	 * returns it as an int.
+	 * 
+	 * @return int the next unsigned byte value from the source stream.
+	 * 
+	 * @throws IOException
+	 *             If a problem occurs reading from this DataInputStream.
+	 * 
+	 * @see DataOutput#writeByte(int)
+	 */
+	public final int readUnsignedByte() throws IOException {
+		int temp = this.read();
+		if (temp >= 0)
+			return temp;
+		throw new EOFException();
+	}
+
+	/**
+	 * Reads a 16-bit unsigned <code>short</code> value from this stream and
+	 * returns it as an int.
+	 * 
+	 * @return int the next unsigned <code>short</code> value from the source
+	 *         stream.
+	 * 
+	 * @throws IOException
+	 *             If a problem occurs reading from this DataInputStream.
+	 * 
+	 * @see DataOutput#writeShort(int)
+	 */
+	public final int readUnsignedShort() throws IOException {
+		byte[] buffer = new byte[2];
+		if (read(buffer, 0, buffer.length) == buffer.length)
+			return ((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff);
+		throw new EOFException();
+	}
+
+	/**
+	 * Reads a UTF format String from this Stream.
+	 * 
+	 * @return String the next UTF String from the source stream.
+	 * 
+	 * @throws IOException
+	 *             If a problem occurs reading from this DataInputStream.
+	 * 
+	 * @see DataOutput#writeUTF(java.lang.String)
+	 */
+	public final String readUTF() throws IOException {
+		int utfSize = readUnsignedShort();
+		if (utfSize == 0) {
+			return new String();
+		}
+		byte[] buf = new byte[utfSize];
+		if (read(buf, 0, buf.length) == buf.length) {
+			return com.ibm.oti.util.Util.convertFromUTF8(buf, 0, utfSize);
+		}
+		throw new EOFException();
+	}
+
+	/**
+	 * Seeks to the position <code>pos</code> in this RandomAccessFile. All
+	 * read/write/skip methods sent will be relative to <code>pos</code>.
+	 * 
+	 * @param pos
+	 *            the desired file pointer position
+	 * 
+	 * @throws IOException
+	 *             If the stream is already closed or another IOException
+	 *             occurs.
+	 */
+	public native void seek(long pos) throws IOException;
+
+	/**
+	 * Set the length of this file to be <code>newLength</code>. If the
+	 * current file is smaller, it will be expanded and the filePosition will be
+	 * set to the new file length. If the <code>newLength</code> is smaller
+	 * then the file will be truncated.
+	 * 
+     * @param newLength
+	 *            the desired file length
+	 * 
+	 * @throws IOException
+	 *             If the stream is already closed or another IOException
+	 *             occurs.
+	 */
+	public void setLength(long newLength) throws IOException {
+		setLengthImpl(newLength);
+	}
+
+	private native void setLengthImpl(long newLength) throws IOException;
+
+	/**
+	 * Skips <code>count</code> number of bytes in this stream. Subsequent
+	 * <code>read()</code>'s will not return these bytes unless
+	 * <code>reset()</code> is used.
+	 * 
+	 * @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 int skipBytes(int count) throws IOException {
+		if (count > 0) {
+			long currentPos = getFilePointer(), eof = length();
+			int newCount = (int) ((currentPos + count > eof) ? eof - currentPos
+					: count);
+			seek(currentPos + newCount);
+			return newCount;
+		}
+		return 0;
+	}
+
+	/**
+	 * Writes the entire contents of the byte array <code>buffer</code> to
+	 * this RandomAccessFile starting at the current file pointer.
+	 * 
+	 * @param buffer
+	 *            the buffer to be written.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs trying to write to this RandomAccessFile.
+	 * 
+	 * @see #read()
+	 * @see #read(byte[])
+	 * @see #read(byte[], int, int)
+	 */
+	public void write(byte[] buffer) throws IOException {
+		write(buffer, 0, buffer.length);
+	}
+
+	/**
+	 * Writes <code>count</code> bytes from the byte array <code>buffer</code>
+	 * starting at <code>offset</code> to this RandomAccessFile starting at
+	 * the current file pointer..
+	 * 
+	 * @param buffer
+	 *            the bytes to be written
+	 * @param offset
+	 *            offset in buffer to get bytes
+	 * @param count
+	 *            number of bytes in buffer to write
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to write to this
+	 *             RandomAccessFile.
+	 * @throws IndexOutOfBoundsException
+	 *             If offset or count are outside of bounds.
+	 * 
+	 * @see #read()
+	 * @see #read(byte[])
+	 * @see #read(byte[], int, int)
+	 * 
+	 */
+	public void write(byte[] buffer, int offset, int count) throws IOException {
+		if (fd != null) {
+			writeImpl(buffer, offset, count, fd.descriptor);
+		} else
+			throw new IOException();
+	}
+
+	private native void writeImpl(byte[] buffer, int offset, int count,
+			long descriptor) throws IOException;
+
+	/**
+	 * Writes the specified byte <code>oneByte</code> to this RandomAccessFile
+	 * starting at the current file pointer. Only the low order byte of
+	 * <code>oneByte</code> is written.
+	 * 
+	 * @param oneByte
+	 *            the byte to be written
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to write to this
+	 *             RandomAccessFile.
+	 * 
+	 * @see #read()
+	 * @see #read(byte[])
+	 * @see #read(byte[], int, int)
+	 */
+	public void write(int oneByte) throws IOException {
+		if (fd != null) {
+			writeByteImpl(oneByte, fd.descriptor);
+		} else
+			throw new IOException();
+	}
+
+	private native void writeByteImpl(int oneByte, long descriptor)
+			throws IOException;
+
+	/**
+	 * Writes a boolean to this output stream.
+	 * 
+	 * @param val
+	 *            the boolean value to write to the OutputStream
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to write to this
+	 *             DataOutputStream.
+	 * 
+	 * @see DataInput#readBoolean()
+	 */
+	public final void writeBoolean(boolean val) throws IOException {
+		write(val ? 1 : 0);
+	}
+
+	/**
+	 * Writes a 8-bit byte to this output stream.
+	 * 
+	 * @param val
+	 *            the byte value to write to the OutputStream
+	 * 
+	 * @throws java.io.IOException
+	 *             If an error occurs attempting to write to this
+	 *             DataOutputStream.
+	 * 
+	 * @see #readByte()
+	 * @see #readUnsignedByte()
+	 */
+	public final void writeByte(int val) throws IOException {
+		write(val & 0xFF);
+	}
+
+	/**
+	 * Writes the low order 8-bit bytes from a String to this output stream.
+	 * 
+	 * @param str
+	 *            the String containing the bytes to write to the OutputStream
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to write to this
+	 *             DataOutputStream.
+	 * 
+	 * @see #read(byte[])
+	 * @see #read(byte[],int,int)
+	 * @see #readFully(byte[])
+	 * @see #readFully(byte[],int,int)
+	 */
+	public final void writeBytes(String str) throws IOException {
+		byte bytes[] = new byte[str.length()];
+		for (int index = 0; index < str.length(); index++)
+			bytes[index] = (byte) (str.charAt(index) & 0xFF);
+		write(bytes);
+	}
+
+	/**
+	 * Writes the specified 16-bit character to the OutputStream. Only the lower
+	 * 2 bytes are written with the higher of the 2 bytes written first. This
+	 * represents the Unicode value of val.
+	 * 
+	 * @param val
+	 *            the character to be written
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to write to this
+	 *             DataOutputStream.
+	 * 
+	 * @see DataInput#readChar()
+	 */
+	public final void writeChar(int val) throws IOException {
+		byte[] buffer = new byte[2];
+		buffer[0] = (byte) (val >> 8);
+		buffer[1] = (byte) val;
+		write(buffer, 0, buffer.length);
+	}
+
+	/**
+	 * Writes the specified 16-bit characters contained in str to the
+	 * OutputStream. Only the lower 2 bytes of each character are written with
+	 * the higher of the 2 bytes written first. This represents the Unicode
+	 * value of each character in str.
+	 * 
+	 * @param str
+	 *            the String whose characters are to be written.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to write to this
+	 *             DataOutputStream.
+	 * 
+	 * @see DataInput#readChar()
+	 */
+	public final void writeChars(String str) throws IOException {
+		byte newBytes[] = new byte[str.length() * 2];
+		for (int index = 0; index < str.length(); index++) {
+			int newIndex = index == 0 ? index : index * 2;
+			newBytes[newIndex] = (byte) ((str.charAt(index) >> 8) & 0xFF);
+			newBytes[newIndex + 1] = (byte) (str.charAt(index) & 0xFF);
+		}
+		write(newBytes);
+	}
+
+	/**
+	 * Writes a 64-bit double to this output stream. The resulting output is the
+	 * 8 bytes resulting from calling Double.doubleToLongBits().
+	 * 
+	 * @param val
+	 *            the double to be written.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to write to this
+	 *             DataOutputStream.
+	 * 
+	 * @see DataInput#readDouble()
+	 */
+	public final void writeDouble(double val) throws IOException {
+		writeLong(Double.doubleToLongBits(val));
+	}
+
+	/**
+	 * Writes a 32-bit float to this output stream. The resulting output is the
+	 * 4 bytes resulting from calling Float.floatToIntBits().
+	 * 
+	 * @param val
+	 *            the float to be written.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to write to this
+	 *             DataOutputStream.
+	 * 
+	 * @see DataInput#readFloat()
+	 */
+	public final void writeFloat(float val) throws IOException {
+		writeInt(Float.floatToIntBits(val));
+	}
+
+	/**
+	 * Writes a 32-bit int to this output stream. The resulting output is the 4
+	 * bytes, highest order first, of val.
+	 * 
+	 * @param val
+	 *            the int to be written.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to write to this
+	 *             DataOutputStream.
+	 * 
+	 * @see DataInput#readInt()
+	 */
+	public final void writeInt(int val) throws IOException {
+		byte[] buffer = new byte[4];
+		buffer[0] = (byte) (val >> 24);
+		buffer[1] = (byte) (val >> 16);
+		buffer[2] = (byte) (val >> 8);
+		buffer[3] = (byte) val;
+		write(buffer, 0, buffer.length);
+	}
+
+	/**
+	 * Writes a 64-bit long to this output stream. The resulting output is the 8
+	 * bytes, highest order first, of val.
+	 * 
+	 * @param val
+	 *            the long to be written.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to write to this
+	 *             DataOutputStream.
+	 * 
+	 * @see DataInput#readLong()
+	 */
+	public final void writeLong(long val) throws IOException {
+		byte[] buffer = new byte[8];
+		int t = (int) (val >> 32);
+		buffer[0] = (byte) (t >> 24);
+		buffer[1] = (byte) (t >> 16);
+		buffer[2] = (byte) (t >> 8);
+		buffer[3] = (byte) t;
+		buffer[4] = (byte) (val >> 24);
+		buffer[5] = (byte) (val >> 16);
+		buffer[6] = (byte) (val >> 8);
+		buffer[7] = (byte) val;
+		write(buffer, 0, buffer.length);
+	}
+
+	/**
+	 * Writes the specified 16-bit short to the OutputStream. Only the lower 2
+	 * bytes are written with the higher of the 2 bytes written first.
+	 * 
+	 * @param val
+	 *            the short to be written
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to write to this
+	 *             DataOutputStream.
+	 * 
+	 * @see DataInput#readShort()
+	 * @see DataInput#readUnsignedShort()
+	 */
+	public final void writeShort(int val) throws IOException {
+		writeChar(val);
+	}
+
+	/**
+	 * Writes the specified String out in UTF format.
+	 * 
+	 * @param str
+	 *            the String to be written in UTF format.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting to write to this
+	 *             DataOutputStream.
+	 * 
+	 * @see DataInput#readUTF()
+	 */
+	public final void writeUTF(String str) throws IOException {
+		int utfCount = 0, length = str.length();
+		for (int i = 0; i < length; i++) {
+			int charValue = str.charAt(i);
+			if (charValue > 0 && charValue <= 127)
+				utfCount++;
+			else if (charValue <= 2047)
+				utfCount += 2;
+			else
+				utfCount += 3;
+		}
+		if (utfCount <= 65535) {
+			byte utfBytes[] = new byte[utfCount + 2];
+			int utfIndex = 2;
+			for (int i = 0; i < length; i++) {
+				int charValue = str.charAt(i);
+				if (charValue > 0 && charValue <= 127) {
+					utfBytes[utfIndex++] = (byte) charValue;
+				} else if (charValue <= 2047) {
+					utfBytes[utfIndex++] = (byte) (0xc0 | (0x1f & (charValue >> 6)));
+					utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & charValue));
+				} else {
+					utfBytes[utfIndex++] = (byte) (0xe0 | (0x0f & (charValue >> 12)));
+					utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & (charValue >> 6)));
+					utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & charValue));
+				}
+			}
+			utfBytes[0] = (byte) (utfCount >> 8);
+			utfBytes[1] = (byte) utfCount;
+			write(utfBytes);
+		} else
+			throw new UTFDataFormatException(com.ibm.oti.util.Msg
+					.getString("K0068")); //$NON-NLS-1$
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/Reader.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/Reader.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/Reader.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/Reader.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,230 @@
+/* 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;
+
+
+/**
+ * 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 {
+	/**
+	 * The object used to syncronize 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();
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/SequenceInputStream.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/SequenceInputStream.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/SequenceInputStream.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/SequenceInputStream.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,187 @@
+/* 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;
+
+
+/**
+ * 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.
+	 */
+	java.util.Enumeration 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 && s2 != null) {
+			java.util.Vector inVector = new java.util.Vector(1);
+			inVector.addElement(s2);
+			e = inVector.elements();
+			in = s1;
+		} else
+			throw new NullPointerException();
+	}
+
+	/**
+	 * 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(java.util.Enumeration e) {
+		this.e = e;
+		if (e.hasMoreElements()) {
+			in = (InputStream) 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 {
+		if (e != null) {
+			while (in != null)
+				nextStream();
+			e = null;
+		} else
+			throw new IOException(com.ibm.oti.util.Msg.getString("K00b7")); //$NON-NLS-1$
+	}
+
+	/**
+	 * 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 = (InputStream) 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 the stream is already closed or another IOException
+	 *             occurs.
+	 */
+	public int read(byte[] buffer, int offset, int count) throws IOException {
+		if (buffer == null) {
+			// avoid int overflow
+			if (offset >= 0 && count >= 0) {
+				while (in != null) {
+					long result = in.skip(count);
+					if (result >= 0)
+						return (int) result;
+					nextStream();
+				}
+			} else
+				throw new ArrayIndexOutOfBoundsException();
+		} else {
+			// avoid int overflow
+			if (0 <= offset && offset <= buffer.length && 0 <= count
+					&& count <= buffer.length - offset) {
+				while (in != null) {
+					int result = in.read(buffer, offset, count);
+					if (result >= 0)
+						return result;
+					nextStream();
+				}
+			} else
+				throw new ArrayIndexOutOfBoundsException();
+		}
+		return -1;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/Serializable.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/Serializable.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/Serializable.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/Serializable.java Wed Nov 30 21:29:27 2005
@@ -0,0 +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 */
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/SerializablePermission.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/SerializablePermission.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/SerializablePermission.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/SerializablePermission.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,58 @@
+/* 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;
+
+
+/**
+ * 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 java.security.BasicPermission {
+	static final long serialVersionUID = 8537212141160296410L;
+
+	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);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StreamCorruptedException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StreamCorruptedException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StreamCorruptedException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StreamCorruptedException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +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 {
+
+	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);
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StreamTokenizer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StreamTokenizer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StreamTokenizer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StreamTokenizer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +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) {
+			StringBuffer digits = new StringBuffer(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
+		StringBuffer result = new StringBuffer();
+		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;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StringBufferInputStream.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StringBufferInputStream.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StringBufferInputStream.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StringBufferInputStream.java Wed Nov 30 21:29:27 2005
@@ -0,0 +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(com.ibm.oti.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;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StringReader.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StringReader.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StringReader.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StringReader.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,216 @@
+/* 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;
+
+
+/**
+ * StringReader is used as a character input stream on a String.
+ * 
+ * @see StringWriter
+ */
+public class StringReader extends Reader {
+	private String str;
+
+	private int markpos = -1;
+
+	private int pos = 0;
+
+	private int count;
+
+	/**
+	 * Construct a StringReader on the String <code>str</code>. The size of
+	 * the reader is set to the <code>length()</code> of the String and the
+	 * Object to synchronize access through is set to <code>str</code>.
+	 * 
+	 * @param str
+	 *            the String to filter reads on.
+	 */
+	public StringReader(String str) {
+		super(str);
+		this.str = str;
+		this.count = str.length();
+	}
+
+	/**
+	 * This method closes this StringReader. Once it is closed, you can no
+	 * longer read from it. Only the first invocation of this method has any
+	 * effect.
+	 */
+	public void close() {
+		synchronized (lock) {
+			if (isOpen())
+				str = null;
+		}
+	}
+
+	/**
+	 * Answer a boolean indicating whether or not this StringReader is open.
+	 * @return str
+	 */
+	private boolean isOpen() {
+		return str != null;
+	}
+
+	/**
+	 * Set a Mark position in this Reader. The parameter <code>readLimit</code>
+	 * is ignored for StringReaders. Sending reset() will reposition the reader
+	 * back to the marked position provided the mark has not been invalidated.
+	 * 
+	 * @param readLimit
+	 *            ignored for StringReaders.
+	 * 
+	 * @throws IOException
+	 *             If an error occurs attempting mark this StringReader.
+	 */
+	public void mark(int readLimit) throws IOException {
+		if (readLimit >= 0) {
+			synchronized (lock) {
+				if (isOpen())
+					markpos = pos;
+				else
+					throw new IOException(com.ibm.oti.util.Msg
+							.getString("K0083")); //$NON-NLS-1$
+			}
+		} else
+			throw new IllegalArgumentException();
+	}
+
+	/**
+	 * Answers a boolean indicating whether or not this StringReader supports
+	 * mark() and reset(). This method always returns true.
+	 * 
+	 * @return <code>true</code> if mark() and reset() are supported,
+	 *         <code>false</code> otherwise. This implementation always
+	 *         returns <code>true</code>.
+	 */
+	public boolean markSupported() {
+		return true;
+	}
+
+	/**
+	 * Reads a single character from this StringReader and returns the result as
+	 * an int. The 2 higher-order bytes 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 StringReader is already closed.
+	 */
+	public int read() throws IOException {
+		synchronized (lock) {
+			if (isOpen()) {
+				if (pos != count) {
+					return str.charAt(pos++);
+				}
+				return -1;
+			}
+			throw new IOException(com.ibm.oti.util.Msg.getString("K0083")); //$NON-NLS-1$
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.Reader#read(char[], int, int)
+	 */
+	public int read(char buf[], int offset, int len) throws IOException {
+		// avoid int overflow
+		if (0 <= offset && offset <= buf.length && 0 <= len
+				&& len <= buf.length - offset) {
+			synchronized (lock) {
+				if (isOpen()) {
+					if (pos == this.count) {
+						return -1;
+					}
+					int end = pos + len > this.count ? this.count : pos + len;
+					str.getChars(pos, end, buf, offset);
+					int read = end - pos;
+					pos = end;
+					return read;
+				}
+				throw new IOException(com.ibm.oti.util.Msg.getString("K0083")); //$NON-NLS-1$
+			}
+		}
+		throw new ArrayIndexOutOfBoundsException();
+	}
+
+	/**
+	 * Answers a <code>boolean</code> indicating whether or not this
+	 * StringReader 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. The implementation in StringReader always
+	 * returns <code>true</code> even when it has been closed.
+	 * 
+	 * @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 an IO error occurs.
+	 */
+	public boolean ready() throws IOException {
+		synchronized (lock) {
+			if (isOpen())
+				return true;
+			throw new IOException(com.ibm.oti.util.Msg.getString("K0083")); //$NON-NLS-1$
+		}
+	}
+
+	/**
+	 * Reset this StringReader's 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 StringReader is
+	 * reset to the beginning of the String.
+	 * 
+	 * @throws IOException
+	 *             If this StringReader has already been closed.
+	 */
+	public void reset() throws IOException {
+		synchronized (lock) {
+			if (isOpen())
+				pos = markpos != -1 ? markpos : 0;
+			else
+				throw new IOException(com.ibm.oti.util.Msg.getString("K0083")); //$NON-NLS-1$
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.Reader#skip(long)
+	 */
+	public long skip(long ns) throws IOException {
+		synchronized (lock) {
+			if (isOpen()) {
+				if (ns <= 0) {
+					return 0;
+				}
+				long skipped = 0;
+				if (ns < this.count - pos) {
+					pos = pos + (int) ns;
+					skipped = ns;
+				} else {
+					skipped = this.count - pos;
+					pos = this.count;
+				}
+				return skipped;
+			}
+			throw new IOException(com.ibm.oti.util.Msg.getString("K0083")); //$NON-NLS-1$
+		}
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StringWriter.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StringWriter.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StringWriter.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/io/StringWriter.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,177 @@
+/* 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;
+
+
+/**
+ * StringWriter is an class for writing Character Streams to a StringBuffer. The
+ * characters written can then be returned as a String. This is used for
+ * capturing output sent to a Writer by substituting a StringWriter.
+ * 
+ * @see StringReader
+ */
+public class StringWriter extends Writer {
+	private StringBuffer buf;
+
+	/**
+	 * Constructs a new StringWriter which has a StringBuffer allocated with the
+	 * default size of 16 characters. The StringBuffer is also the
+	 * <code>lock</code> used to synchronize access to this Writer.
+	 */
+	public StringWriter() {
+		super();
+		buf = new StringBuffer(16);
+		lock = buf;
+	}
+
+	/**
+	 * Constructs a new StringWriter which has a StringBuffer allocated with the
+	 * size of <code>initialSize</code> characters. The StringBuffer is also
+	 * the <code>lock</code> used to synchronize access to this Writer.
+	 * 
+	 * @param initialSize
+	 *            the intial number of characters
+	 */
+	public StringWriter(int initialSize) {
+		if (initialSize >= 0) {
+			buf = new StringBuffer(initialSize);
+			lock = buf;
+		} else
+			throw new IllegalArgumentException();
+	}
+
+	/**
+	 * Close this Writer. This is the concrete implementation required. This
+	 * particular implementation does nothing.
+	 * 
+	 * @throws IOException
+	 *             If an IO error occurs closing this StringWriter.
+	 */
+	public void close() throws IOException {
+		/*empty*/
+	}
+
+	/**
+	 * Flush this Writer. This is the concrete implementation required. This
+	 * particular implementation does nothing.
+	 */
+	public void flush() {
+		/*empty*/
+	}
+
+	/**
+	 * Answer the contents of this StringWriter as a StringBuffer. Any changes
+	 * made to the StringBuffer by the receiver or the caller are reflected in
+	 * this StringWriter.
+	 * 
+	 * @return this StringWriters local StringBuffer.
+	 */
+	public StringBuffer getBuffer() {
+		synchronized (lock) {
+			return buf;
+		}
+	}
+
+	/**
+	 * Answer the contents of this StringWriter as a String. Any changes made to
+	 * the StringBuffer by the receiver after returning will not be reflected in
+	 * the String returned to the caller.
+	 * 
+	 * @return this StringWriters current contents as a String.
+	 */
+	public String toString() {
+		synchronized (lock) {
+			return buf.toString();
+		}
+	}
+
+	/**
+	 * Writes <code>count</code> characters starting at <code>offset</code>
+	 * in <code>cbuf</code> to this StringWriter.
+	 * 
+	 * @param cbuf
+	 *            the non-null array containing characters to write.
+	 * @param offset
+	 *            offset in buf to retrieve characters
+	 * @param count
+	 *            maximum number of characters to write
+	 * 
+	 * @throws ArrayIndexOutOfBoundsException
+	 *             If offset or count are outside of bounds.
+	 */
+	public void write(char[] cbuf, int offset, int count) {
+		// avoid int overflow
+		if (0 <= offset && offset <= cbuf.length && 0 <= count
+				&& count <= cbuf.length - offset) {
+			synchronized (lock) {
+				this.buf.append(cbuf, offset, count);
+			}
+		} else {
+			throw new ArrayIndexOutOfBoundsException();
+		}
+	}
+
+	/**
+	 * Writes the specified character <code>oneChar</code> to this
+	 * StringWriter. This implementation writes the low order two bytes to the
+	 * Stream.
+	 * 
+	 * @param oneChar
+	 *            The character to write
+	 * 
+	 */
+	public void write(int oneChar) {
+		synchronized (lock) {
+			buf.append((char) oneChar);
+		}
+	}
+
+	/**
+	 * Writes the characters from the String <code>str</code> to this
+	 * StringWriter.
+	 * 
+	 * @param str
+	 *            the non-null String containing the characters to write.
+	 * 
+	 */
+	public void write(String str) {
+		synchronized (lock) {
+			buf.append(str);
+		}
+	}
+
+	/**
+	 * Writes <code>count</code> number of characters starting at
+	 * <code>offset</code> from the String <code>str</code> to this
+	 * StringWriter.
+	 * 
+	 * @param str
+	 *            the non-null String containing the characters to write.
+	 * @param offset
+	 *            the starting point to retrieve characters.
+	 * @param count
+	 *            the number of characters to retrieve and write.
+	 * 
+	 * @throws ArrayIndexOutOfBoundsException
+	 *             If offset or count are outside of bounds.
+	 */
+	public void write(String str, int offset, int count) {
+		String sub = str.substring(offset, offset + count);
+		synchronized (lock) {
+			buf.append(sub);
+		}
+	}
+}



Mime
View raw message