/************************************************************************
* *
* java.io *
* *
* Interfaces: *
* DataInput ObjectInput *
* DataOutput ObjectInputValidation *
* Externalizable ObjectOutput *
* FilenameFilter Serializable *
* *
* Classes: *
* BufferedInputStream LineNumberReader *
* BufferedOutputStream ObjectInputStream *
* BufferedReader ObjectOutputStream *
* BufferedWriter ObjectStreamClass *
* ByteArrayInputStream OutputStream *
* ByteArrayOutputStream OutputStreamWriter *
* CharArrayReader PipedInputStream *
* CharArrayWriter PipedOutputStream *
* DataInputStream PipedReader *
* DataOutputStream PipedWriter *
* File PrintStream *
* FileDescriptor PrintWriter *
* FileInputStream PushbackInputStream *
* FileOutputStream PushbackReader *
* FileReader RandomAccessFile *
* FileWriter Reader *
* FilterInputStream SequenceInputStream *
* FilterOutputStream StreamTokenizer *
* FilterReader StringBufferInputStream *
* FilterWriter StringReader *
* InputStream StringWriter *
* InputStreamReader Writer *
* LineNumberInputStream *
* *
* Exceptions: *
* CharConversionException NotSerializableException *
* EOFException ObjectStreamException *
* FileNotFoundException OptionalDataException *
* IOException StreamCorruptedException *
* InterruptedIOException SyncFailedException *
* InvalidClassException UTFDataFormatException *
* InvalidObjectException UnsupportedEncodingException *
* NotActiveException WriteAbortedException *
* *
************************************************************************/
package Test.Chris;
import java.io.*;
public class Java_io {
public void exercise() {
file();
// byte output stream
outputstream();
fileoutputstream();
bytearrayoutputstream();
pipedoutputstream();
filteroutputstream();
bufferedoutputstream();
printstream();
dataoutputstream();
// unicode output stream
writer();
outputstreamwriter();
filewriter();
chararraywriter();
stringwriter();
pipedwriter();
filterwriter();
bufferedwriter();
printwriter();
// byte input stream
inputstream();
fileinputstream();
bytearrayinputstream();
pipedinputstream();
filterinputstream();
bufferedinputstream();
datainputstream();
pushbackinputstream();
linenumberinputstream();
sequenceinputstream();
stringbufferinputstream();
// unicode input stream
reader();
inputstreamreader();
filereader();
chararrayreader();
stringreader();
pipedreader();
filterreader();
pushbackreader();
bufferedreader();
linenumberreader();
randomaccessfile();
objectoutputstream();
objectinputstream();
objectstreamclass();
filedescriptor();
streamtokenizer();
// interfaces
datainput();
dataoutput();
externalizable();
objectinput();
objectinputvalidation();
objectoutput();
}
/*********************************************************************
* *
* File: *
* *
* Desc: An object of File class represents either a file that *
* will be accessed for input/output or a directory *
* *
* Vars: *
* pathSeparator separator separatorChar *
* pathSeparatorChar *
* *
* Methods: *
* canRead getName lastModified *
* canWrite getParent length *
* delete getPath list *
* equals hashCode mkdir *
* exists isAbsolute mkdirs *
* getAbsolutePath isDirectory renameTo *
* getCanonicalPath isFile toString *
* *
*********************************************************************/
void file() {
int i;
long n;
boolean b;
char c;
String s;
String[] a;
c = File.separatorChar; // file seperator "\"
s = File.separator;
c = File.pathSeparatorChar; // path seperarator ";"
s = File.pathSeparator;
File xd = new File("io"); // create object to access directory
File xf = new File("io/File.txt");// create object to access file
File xs = new File("io/temp");
xd.mkdir(); // creates directory specified by File object
xs.mkdirs(); // creates directory including any necessary parent directories
b = xd.exists(); // tests if File exists
b = xd.isDirectory(); // tests if File is directory
b = xd.isFile(); // tests if File is a "normal" file
b = xd.equals(xf); // compares this object against the specified object
b = xd.canRead(); // tests if application can read from file
b = xd.canWrite(); // tests if application can write to file
b = xd.isAbsolute(); // tests if file is an absolute pathname
s = xd.getName(); // name of the file
s = xd.getParent(); // parent part of File pathname or null if no parent part
s = xd.getPath(); // pathname file
s = xd.getAbsolutePath(); // absolute pathname of the file
try {
s = xd.getCanonicalPath(); // canonical form of pathname
} catch(IOException e) { System.out.println(e);
}
n = xd.length(); // file length
a = xd.list(); // directory listing
a = xd.list(new filenamefilter("t", "txt")); // directory listing with FilenameFilter
n = xd.lastModified(); // time file was last modified
b = xf.renameTo(xs); // move file to the pathname given by File argument
xs.delete(); // deletes the file specified by this object
//xd.delete();
i = xd.hashCode(); // computes a hashcode for the file
s = xd.toString(); // returns string representation of this object
}
/*********************************************************************
* *
* FilenameFilter: (interface) *
* *
* Desc: An interface used to create file list filter *
* *
* Methods: *
* accept *
* *
*********************************************************************/
class filenamefilter implements FilenameFilter {
private String name;
private String extension;
public filenamefilter(String name, String extension) {
this.name = name.toLowerCase();
this.extension = extension.toLowerCase();
}
public boolean accept(File directory, String filename) {
boolean ok = true;
if (name != null) ok &= filename.toLowerCase().startsWith(name);
if (extension != null) ok &= filename.toLowerCase().endsWith("." + extension);
return ok;
}
}
/*********************************************************************
* *
* OutputStream: (abstract) *
* *
* Desc: Base abstract class for byte stream output *
* *
* Methods: *
* close flush write *
* *
*********************************************************************/
class ChrisOutputStream extends OutputStream {
/*
*
* Derived Subclasses:
*
* FileOutputStream
* ByteArrayOutputStream
* PipedOutputStream
* FilterOutputStream
* ObjectOutputStream
*
*/
FileOutputStream ios;
public ChrisOutputStream(String s) throws IOException {
ios = new FileOutputStream(s);
}
public void write(int b) throws IOException {
ios.write(b);
}
public void write(byte b[]) throws IOException {
for (int i = 0; i < b.length; i++) write(b[i]);
}
public void write(byte b[], int off, int len) throws IOException {
for (int i = off; (i < b.length) && (i < off+len); i++) write(b[i]);
}
public void flush() throws IOException {
ios.flush();
}
public void close() throws IOException {
ios.close();
}
}
void outputstream() {
byte[] b = {0x31, 0x32, 0x33, 0x34};
try {
ChrisOutputStream ios = new ChrisOutputStream("io/OutputStream.txt");
ios.write(0x30); // writes the specified char to output stream
ios.write(b);
ios.write(b, 2, 1);
ios.write(0x39);
ios.flush(); // flushes output stream and forces any buffered output to be written
ios.close(); // closes output stream and releases system resources
} catch(IOException e) { System.out.println(e);
}
}
/*********************************************************************
* *
* FileOutputStream: (extends OutputStream) *
* *
* Desc: Defines a byte output stream to file *
* *
* Methods: *
* close getFD write *
* finalize *
* *
*********************************************************************/
void fileoutputstream() {
FileDescriptor fd;
byte[] b = {0x31, 0x32, 0x33, 0x34};
try {
FileOutputStream ios = new FileOutputStream("io/FileOutputStream.txt");
ios.write(0x30); // writes the specified char to output stream
ios.write(b);
ios.write(b, 2, 1);
ios.write(0x39);
fd = ios.getFD(); // returns the file descriptor associated with this stream
ios.close(); // closes output stream and releases system resources
} catch(IOException e) { System.out.println(e);
}
}
/*********************************************************************
* *
* ByteArrayOutputStream: (extends OutputStream) *
* *
* Desc: Defines a byte output stream to array *
* *
* Methods: *
* reset toByteArray write *
* size toString writeTo *
* *
*********************************************************************/
void bytearrayoutputstream() {
int n;
String s;
byte[] b = {0x31, 0x32, 0x33, 0x34};
ByteArrayOutputStream ios = new ByteArrayOutputStream(25); // initial array size
ios.write(0x30); // writes the specified char to output stream
try {
ios.write(b); // inherited method
} catch (IOException e) {
}
ios.write(b, 2, 1);
ios.write(0x39);
s = ios.toString(); // converts the buffer's contents into a string
b = ios.toByteArray(); // creates a newly allocated byte array
n = ios.size(); // current size of the buffer
try {
ChrisOutputStream xf = new ChrisOutputStream("io/ByteArrayOutputStream.txt");
ios.writeTo(xf); // writes contents of byte array output stream to specifed stream
} catch (IOException e) {
}
ios.reset(); // resets count field to zero, all accumulated output is discarded
}
/*********************************************************************
* *
* PipedOutputStream: (extends OutputStream) *
* *
* Desc: Defines a byte output stream to Pipe *
* *
* Methods: *
* close flush write *
* connect *
* *
*********************************************************************/
void pipedoutputstream() {
byte[] b = {0x31, 0x32, 0x33, 0x34};
PipedOutputStream ios = new PipedOutputStream();
PipedInputStream xr = new PipedInputStream();
try {
ios.connect(xr); // Connects this piped output stream to a receiver
ios.write(0x30); // writes the specified char to output stream
ios.write(b);
ios.write(b, 2, 1);
ios.write(0x39);
ios.flush(); // forces any buffered output bytes to be written out
ios.close(); // closes output stream and releases system resources
} catch (IOException e) {
}
}
/*********************************************************************
* *
* FilterOutputStream: (extends OutputStream) *
* *
* Desc: Base class to extend other output streams *
* *
* Methods: *
* close flush write *
* *
*********************************************************************/
void filteroutputstream() {
/*
*
* This class usually acts as an intermediate layer between OutputStream and
* the derived subclasses:
*
* BufferedOutputStream
* DataOutputStream
* PrintStream
* CheckedOutputStream (java.util)
* InflaterOutputStream (java.util)
* ZipOutputStream (java.util)
* GZIPOutputStream (java.util)
* DigestOutputStream (java.security)
*
*/
byte[] b = {0x31, 0x32, 0x33, 0x34};
try {
FilterOutputStream ios = new FilterOutputStream(new ChrisOutputStream("io/FilterOutputStream.txt"));
ios.write(0x30); // writes the specified char to output stream
ios.write(b);
ios.write(b, 2, 1);
ios.write(0x39);
ios.flush(); // forces any buffered output bytes to be written out
ios.close(); // closes output stream and releases system resources
} catch(IOException e) { System.out.println(e);
}
}
/*********************************************************************
* *
* BufferedOutputStream: (extends FilterOutputStream) *
* *
* Desc: Adds buffering to an output stream *
* *
* Methods: *
* flush write *
* *
*********************************************************************/
void bufferedoutputstream() {
// Used to add buffering capabilities to the byte Output Streams
byte[] b = {0x31, 0x32, 0x33, 0x34};
try {
BufferedOutputStream ios =
new BufferedOutputStream(new ChrisOutputStream("io/BufferedOutputStream.txt"), 4096);
ios.write(0x30); // writes the specified char to output stream
ios.write(b);
ios.write(b, 2, 1);
ios.write(0x39);
ios.flush(); // forces any buffered output bytes to be written out
} catch(IOException e) { System.out.println(e);
}
}
/*********************************************************************
* *
* DataOutputStream: (extends FilterOutputStream) *
* *
* Desc: Enable write of any of the basic types of data *
* *
* Methods: *
* flush writeBytes writeInt *
* size writeChar writeLong *
* write writeChars writeShort *
* writeBoolean writeDouble writeUTF *
* writeByte writeFloat *
* *
*********************************************************************/
void dataoutputstream() {
int n;
byte[] b = {0x31, 0x32, 0x33, 0x34};
// all data is written as stream of bytes to the OutputStream
try {
DataOutputStream ios = new DataOutputStream(new ChrisOutputStream("io/DataOutputStream.txt"));
ios.write(0x30); // writes the specified char to output stream
ios.write(b);
ios.write(b, 2, 1);
ios.writeBoolean(true); // writes boolean (1 byte)
ios.writeByte(0x30); // writes byte (1 byte)
ios.writeChar('A'); // writes char (2 bytes)
ios.writeShort(567); // writes short (2 bytes)
ios.writeInt(1234); // writes int (4 bytes)
ios.writeLong(4321L); // writes long (8 bytes)
ios.writeFloat(3.21f); // writes float (4 bytes)
ios.writeDouble(1.23); // writes double (8 bytes)
ios.writeUTF("Fred"); // writes UTF-8 encoded string
ios.writeBytes("Hello"); // writes string (1 byte per char)
ios.writeChars("ABC"); // writes string (2 bytes per char)
ios.write(b);
ios.write(b, 2, 1);
ios.writeByte(0x35);
ios.writeShort(765);
ios.write(0x38);
ios.write(0x39);
n = ios.size(); // number of bytes written to output stream
ios.flush(); // forces any buffered output bytes to be written out
ios.close(); // closes output stream and releases system resources
} catch(IOException e) { System.out.println(e);
}
}
/*********************************************************************
* *
* PrintStream: (extends OutputStream) *
* *
* Desc: Print values/objects to output stream - deprecated *
* *
* Methods: *
* checkError print write *
* close println *
* flush setError *
* *
*********************************************************************/
void printstream() {
/* This class has been deprecated - use PrintWriter instead
boolean b;
byte[] c = {0x31, 0x32, 0x33, 0x34};
PrintStream ios = new PrintStream(new ChrisOutputStream("io/PrintStream.txt"));
ios.print(true); // print to output stream
ios.print('A');
ios.print(c);
ios.print(4);
ios.print(5L);
ios.print(1.23f);
ios.print(3.21);
ios.print("hello");
ios.println();
ios.println(true);
ios.println('A');
ios.println(c);
ios.println(4);
ios.println(5L);
ios.println(1.23f);
ios.println(3.21);
ios.println("hello");
ios.write(0x30);
ios.write(c, 0, 2);
b = ios.checkError(); // flush the stream and check its error state
ios.flush(); // forces any buffered output bytes to be written out
ios.close(); // closes output stream and releases system resources
*/
/* TO BE DETERMINED
print(Object) // Print an object
println(Object) // Print an Object, and then finish the line
setError() // Indicate that an error has occurred
*/
}
/*********************************************************************
* *
* Writer: (abstract) *
* *
* Desc: Base abstract class for writing characters *
* *
* Methods: *
* close flush write *
* *
*********************************************************************/
class ChrisWriter extends Writer {
/*
*
* Derived Subclasses:
*
* OutputStreamWriter
* FileWriter
* StringWriter
* CharArrayWriter
* PipedWriter
* PrintWriter
* BufferedWriter
* FilterWriter
*
*/
DataOutputStream xf;
public ChrisWriter(String s) throws IOException {
xf = new DataOutputStream(new ChrisOutputStream(s));
}
public void write(int b) throws IOException {
xf.writeChar(b);
}
public void write(char b) throws IOException {
xf.writeChar(b);
}
public void write(char b[], int off, int len) throws IOException {
for (int i = off; i < (off+len); i++) xf.writeChar(b[i]);
}
public void write(String b, int off, int len) throws IOException {
xf.writeChars(b.substring(off, off+len));
}
public void write(String b) throws IOException {
xf.writeChars(b);
}
public void flush() throws IOException {
xf.flush();
}
public void close() throws IOException {
xf.close();
}
}
void writer() {
char[] c = {'a', 'b', 'c', 'd'};
try {
ChrisWriter ios = new ChrisWriter("io/Writer.txt");
ios.write(0x30); // writes the specified char to output stream
ios.write('1');
ios.write(c, 2, 1);
ios.write("hello");
ios.write("TUVWXYZ", 4, 2);
ios.flush(); // flushes output stream and forces any buffered output to be written
ios.close(); // closes output stream and releases system resources
} catch(IOException e) { System.out.println(e);
}
}
/*********************************************************************
* *
* OutputStreamWriter: (extends Writer) *
* *
* Desc: Enables writing char stream to byte stream *
* *
* Methods: *
* close getEncoding write *
* flush *
* *
*********************************************************************/
void outputstreamwriter() {
char[] c = {'a', 'b', 'c', 'd'};
try {
OutputStreamWriter ios = new OutputStreamWriter(new ChrisOutputStream("io/OutputStreamWriter.txt"));
String s = ios.getEncoding(); // the name of the encoding being used by this stream
ios.write(0x30); // writes the specified char to output stream
ios.write('1');
ios.write(c, 2, 1);
ios.write("hello");
ios.write("TUVWXYZ", 4, 2);
ios.flush(); // flushes output stream and forces any buffered output to be written
ios.close(); // closes output stream and releases system resources
} catch(IOException e) { System.out.println(e);
}
}
/*********************************************************************
* *
* FileWriter: (extends OutputStreamWriter) *
* *
* Desc: Outputs char stream to file *
* *
*********************************************************************/
void filewriter() {
char[] c = {'a', 'b', 'c', 'd'};
try {
FileWriter ios = new FileWriter("io/FileWriter.txt", true); // append flag can be used
ios.write(0x30); // writes the specified char to output stream
ios.write('1');
ios.write(c, 2, 1);
ios.write("hello");
ios.write("TUVWXYZ", 4, 2);
ios.flush(); // flushes output stream and forces any buffered output to be written
ios.close(); // closes output stream and releases system resources
} catch(IOException e) { System.out.println(e);
}
}
/*********************************************************************
* *
* CharArrayWriter: (extends Writer) *
* *
* Desc: Outputs char stream to character array *
* *
* Methods: *
* close size write *
* flush toCharArray writeTo *
* reset toString *
* *
*********************************************************************/
void chararraywriter() {
int n;
String s;
char[] c = {'a', 'b', 'c', 'd'};
CharArrayWriter ios = new CharArrayWriter(25); // initial array size
ios.write(0x30); // writes the specified char to output stream
ios.write('1');
ios.write(c, 2, 1);
try {
ios.write("hello"); // inherited method
} catch (IOException e) {
}
ios.write("TUVWXYZ", 4, 2);
s = ios.toString(); // converts the buffer's contents into a string
c = ios.toCharArray(); // creates a newly allocated byte array
n = ios.size(); // current size of the buffer
try {
ChrisWriter xf = new ChrisWriter("io/CharArrayWrite.txt");
ios.writeTo(xf); // writes contents of byte array output stream to specifed stream
} catch (IOException e) {
}
ios.flush(); // flushes output stream and forces any buffered output to be written
ios.reset(); // resets count field to zero, all accumulated output is discarded
ios.close(); // closes output stream and releases system resources
}
/*********************************************************************
* *
* StringWriter: (extends Writer) *
* *
* Desc: Outputs char stream to a string buffer *
* *
* Methods: *
* close getBuffer write *
* flush toString *
* *
*********************************************************************/
void stringwriter() {
String s;
StringBuffer t;
char[] c = {'a', 'b', 'c', 'd'};
StringWriter ios = new StringWriter();
ios.write(0x30); // writes the specified char to output stream
ios.write(c, 0, 2);
ios.write('1');
ios.write("hello");
ios.write("TUVWXYZ", 4, 2); // documentation error!!! 4,5 in jdk1.1
s = ios.toString(); // converts the buffer's contents into a string
t = ios.getBuffer(); // Return the string buffer itself
ios.flush(); // flushes output stream and forces any buffered output to be written
try {
ios.close(); // closes output stream and releases system resources
} catch (IOException e) {
}
}
/*********************************************************************
* *
* PipedWriter: (extends Writer) *
* *
* Desc: Defines a char output stream to pipe *
* *
* Methods: *
* close flush write *
* connect *
* *
*********************************************************************/
void pipedwriter() {
char[] c = {'a', 'b', 'c', 'd'};
PipedWriter ios = new PipedWriter();
PipedReader xr = new PipedReader();
try {
ios.connect(xr); // Connects this piped output stream to a receiver
ios.write(0x30); // writes the specified char to output stream
ios.write('1');
ios.write(c, 0, 2);
ios.write("hello");
ios.write("TUVWXYZ", 4, 2); // the documentation is wrong here!!! 5,4 in jdk1.1
ios.flush(); // forces any buffered output bytes to be written out
ios.close(); // closes output stream and releases system resources
} catch (IOException e) {
}
}
/*********************************************************************
* *
* FilterWriter: (abstract) (extends Writer) *
* *
* Desc: Base class to extend other output streams *
* *
* Methods: *
* close flush write *
* *
*********************************************************************/
class ChrisFilterWriter extends FilterWriter {
ChrisFilterWriter(Writer w) {
super(w);
}
}
void filterwriter() {
char[] c = {'a', 'b', 'c', 'd'};
try {
ChrisWriter xc = new ChrisWriter("io/FilterWriter.txt");
ChrisFilterWriter ios = new ChrisFilterWriter(xc);
ios.write(0x30); // writes the specified char to output stream
ios.write('1');
ios.write(c, 0, 2);
ios.write("hello");
ios.write("TUVWXYZ", 4, 2);
ios.flush(); // forces any buffered output bytes to be written out
ios.close(); // closes output stream and releases system resources
} catch(IOException e) { System.out.println(e);
}
}
/*********************************************************************
* *
* BufferedWriter: (extends Writer) *
* *
* Desc: Adds buffering to an output stream *
* *
* Methods: *
* close newLine write *
* flush *
* *
*********************************************************************/
void bufferedwriter() {
// Used to add buffering capabilities to the char Output Streams
char[] c = {'a', 'b', 'c', 'd'};
try {
ChrisWriter xc = new ChrisWriter("io/BufferedWriter.txt");
BufferedWriter ios = new BufferedWriter(xc);
ios.write(0x30); // writes the specified char to output stream
ios.write('1');
ios.write(c, 0, 2);
ios.write("hello");
ios.write("TUVWXYZ", 4, 2);
ios.newLine(); // write a line separator
ios.flush(); // forces any buffered output bytes to be written out
ios.close(); // closes output stream and releases system resources
} catch(IOException e) { System.out.println(e);
}
}
/*********************************************************************
* *
* PrintWriter: (extends Writer) *
* *
* Desc: Print formatted representations of objects *
* *
* Methods: *
* checkError print write *
* close println *
* flush setError *
* *
*********************************************************************/
void printwriter() {
boolean b;
char[] c = {'a', 'b', 'c', 'd'};
try {
PrintWriter ios = new PrintWriter(new ChrisWriter("io/PrintWriter.txt"));
ios.print(true); // print to output stream
ios.print('A');
ios.print(c);
ios.print(4);
ios.print(5L);
ios.print(1.23f);
ios.print(3.21);
ios.print("hello");
ios.println();
ios.println(true);
ios.println('A');
ios.println(c);
ios.println(4);
ios.println(5L);
ios.println(1.23f);
ios.println(3.21);
ios.println("hello");
ios.write(0x30);
ios.write('1');
ios.write(c);
ios.write(c, 0, 2);
ios.write("hello");
ios.write("TUVWXYZ", 4, 2);
b = ios.checkError(); // flush the stream and check its error state
ios.flush(); // forces any buffered output bytes to be written out
ios.close(); // closes output stream and releases system resources
} catch(IOException e) { System.out.println(e);
}
/* TO BE DETERMINED
print(Object) // Print an object
println(Object) // Print an Object, and then finish the line
setError() // Indicate that an error has occurred
*/
}
/*********************************************************************
* *
* InputStream: (abstract) *
* *
* Desc: Base abstract class for byte stream input *
* *
* Methods: *
* available markSupported skip *
* close read *
* mark reset *
* *
*********************************************************************/
class ChrisInputStream extends InputStream {
/*
*
* Derived Subclasses:
*
* FileInputStream
* ByteArrayInputStream
* PipedInputStream
* FilterInputStream
* BufferedInputStream
* DataInputStream
* LineNumberInputStream
* PushbackInputStream
* CheckedInputStream (java.util)
* InflaterInputStream (java.util)
* ZipInputStream (java.util)
* GZIPInputStream (java.util)
* DigestInputStream (java.security)
* SequenceInputStream
* ObjectOutputStream
*
*/
int n = 0;
int nmark = -1;
int nlimit = 0;
byte[] c = {0x30, 0x31, 0x32, 0x33, 0x34, 0x33, 0x39};
public ChrisInputStream(String s) {
n = 0;
}
public int read() throws IOException {
if (n < c.length) {
if (nlimit > 0) nlimit = nlimit - 1;
n = n + 1;
return c[n-1];
} else {
return -1;
}
}
public int read(byte b[]) throws IOException {
int i;
for (i = 0; i < b.length; i++) {
b[i] = (byte)read();
if (b[i] == -1) return i;
}
return i;
}
public int read(byte b[], int off, int len) throws IOException {
int i;
for (i = off; (i < b.length) && (i < off+len); i++) {
b[i] = (byte)read();
if (b[i] == -1) return i - off;
}
return i - off;
}
public long skip(long n) throws IOException {
long i;
for (i = 0; i < n; i++) {
if (read() == -1) return i;
}
return i;
}
public int available() throws IOException {
return 0;
}
public void close() throws IOException {
}
public synchronized void mark(int readlimit) {
nmark = n;
nlimit = readlimit;
}
public synchronized void reset() throws IOException {
if (nlimit > 0) {
n = nmark;
} else {
throw new IOException("reset error");
}
}
public boolean markSupported() {
return true;
}
}
void inputstream() {
int i;
long n;
byte[] b = new byte[4];
try {
ChrisInputStream ios = new ChrisInputStream("io/OutputStream.txt");
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
i = ios.available(); // number of bytes that can be read from this file without blocking
i = ios.read(); // reads a byte of data
i = ios.read(b); // reads up to b.length bytes of data into an array of bytes
i = ios.read(b, 2, 1); // reads up to len bytes of data into an array of bytes
n = ios.skip(1); // skips over and discards n bytes of data from the input stream
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
/*********************************************************************
* *
* FileInputStream: (extends InputStream) *
* *
* Desc: Defines a byte input stream from file *
* *
* Methods: *
* available getFD skip *
* close read *
* *
*********************************************************************/
void fileinputstream() {
int i;
long n;
byte[] b = new byte[4];
FileDescriptor fd;
try {
FileInputStream ios = new FileInputStream("io/FileOutputStream.txt");
fd = ios.getFD(); // returns the file descriptor object associated with this stream
if (ios.markSupported()) { } // tests if this input stream supports the mark and reset methods
i = ios.available(); // number of bytes that can be read from this file without blocking
i = ios.read(); // reads a byte of data
i = ios.read(b); // reads up to b.length bytes of data into an array of bytes
i = ios.read(b, 2, 1); // reads up to len bytes of data into an array of bytes
n = ios.skip(1); // skips over and discards n bytes of data from the input stream
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
/*********************************************************************
* *
* ByteArrayInputStream: (extends InputStream) *
* *
* Desc: Defines a byte input stream from array *
* *
* Methods: *
* available markSupported reset *
* mark read skip *
* *
*********************************************************************/
void bytearrayinputstream() {
int i;
long n;
byte[] b = new byte[4];
byte[] c = {0x30, 0x31, 0x32, 0x33, 0x34, 0x33, 0x39};
ByteArrayInputStream ios = new ByteArrayInputStream(c);
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
i = ios.available(); // number of bytes that can be read from this file without blocking
i = ios.read(); // reads a byte of data
try { // inherited method
i = ios.read(b); // reads up to b.length bytes of data into an array of bytes
} catch(IOException e) { System.out.println(e);
}
i = ios.read(b, 2, 1); // reads up to len bytes of data into an array of bytes
n = ios.skip(1); // skips over and discards n bytes of data from the input stream
try { // inherited method
ios.close(); // closes input stream and releases system resources
} catch(IOException e) { System.out.println(e);
}
}
/*********************************************************************
* *
* PipedInputStream: (extends InputStream) *
* *
* Desc: Defines a byte input stream from Pipe *
* *
* Methods: *
* available connect receive *
* close read *
* *
*********************************************************************/
void pipedinputstream() {
int i;
byte[] b = new byte[4];
byte[] c = {0x30, 0x31, 0x32, 0x33, 0x34, 0x33};
PipedOutputStream xs = new PipedOutputStream();
PipedInputStream ios = new PipedInputStream();
try {
ios.connect(xs); // Connects this piped input stream to a sender
xs.write(c);
if (ios.markSupported()) { } // tests if this input stream supports the mark and reset methods
i = ios.available(); // number of bytes that can be read from this pipe without blocking
i = ios.read(); // reads a byte of data
i = ios.read(b); // reads up to b.length bytes of data into an array of bytes
i = ios.read(b, 2, 1); // reads up to len bytes of data into an array of bytes
ios.close(); // closes input stream and releases system resources
} catch (IOException e) {
}
}
/*********************************************************************
* *
* FilterInputStream: (extends InputStream) *
* *
* Desc: Base class to extend other input streams *
* *
* Methods: *
* available markSupported skip *
* close read *
* mark reset *
* *
*********************************************************************/
class ChrisFilterInputStream extends FilterInputStream {
ChrisFilterInputStream(InputStream ios) {
super(ios); // constructor is protected for this class
}
}
void filterinputstream() {
/*
*
* This class usually acts as an intermediate layer between InputStream and
* the derived subclasses:
*
* BufferedInputStream
* DataInputStream
* LineNumberInputStream
* PushbackInputStream
* CheckedInputStream (java.util)
* InflaterInputStream (java.util)
* ZipInputStream (java.util)
* GZIPInputStream (java.util)
* DigestInputStream (java.security)
*
*/
int i;
long n;
byte[] b = new byte[4];
try {
ChrisInputStream xc = new ChrisInputStream("io/FilterOutputStream.txt");
FilterInputStream ios = new ChrisFilterInputStream((InputStream)xc);
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
i = ios.available(); // number of bytes that can be read from this file without blocking
i = ios.read(); // reads a byte of data
i = ios.read(b); // reads up to b.length bytes of data into an array of bytes
i = ios.read(b, 2, 1); // reads up to len bytes of data into an array of bytes
n = ios.skip(1); // skips over and discards n bytes of data from the input stream
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
/*********************************************************************
* *
* BufferedInputStream: (extends FilterInputStream) *
* *
* Desc: Adds buffering to an input stream *
* *
* Methods: *
* available markSupported reset *
* mark read skip *
* *
*********************************************************************/
void bufferedinputstream() {
int i;
long n;
byte[] b = new byte[4];
try {
BufferedInputStream ios =
new BufferedInputStream(new ChrisInputStream("io/BufferedOutputStream.txt"), 4096);
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
i = ios.available(); // number of bytes that can be read from this file without blocking
i = ios.read(); // reads a byte of data
i = ios.read(b); // reads up to b.length bytes of data into an array of bytes
i = ios.read(b, 2, 1); // reads up to len bytes of data into an array of bytes
n = ios.skip(1); // Skips over and discards n bytes of data from the input stream
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
/*********************************************************************
* *
* DataInputStream: (extends FilterInputStream) *
* *
* Desc: Enable read of any of the basic types of data *
* *
* Methods: *
* read readFloat readShort *
* readBoolean readFully readUnsignedByte *
* readByte readInt readUnsignedShort *
* readChar -readLine readUTF *
* readDouble readLong skipBytes *
* *
*********************************************************************/
void datainputstream() {
boolean f;
char c;
int i;
short j;
long n;
float x;
double y;
String s;
byte[] b = new byte[4];
try {
DataInputStream ios = new DataInputStream(new FileInputStream("io/DataOutputStream.txt"));
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(100); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
i = ios.available(); // number of bytes that can be read from this file without blocking
i = ios.read(); // reads a byte of data
i = ios.read(b); // reads up to b.length bytes of data into an array of bytes
i = ios.read(b, 2, 1); // reads up to len bytes of data into an array of bytes
f = ios.readBoolean(); // reads boolean (1 byte)
b[0] = ios.readByte(); // reads byte (1 byte)
c = ios.readChar(); // reads char (2 bytes)
j = ios.readShort(); // reads short (2 bytes)
i = ios.readInt(); // reads int (4 bytes)
n = ios.readLong(); // reads long (8 bytes)
x = ios.readFloat(); // reads float (4 bytes)
y = ios.readDouble(); // reads double (8 bytes)
s = ios.readUTF(); // reads UTF-8 encoded string
n = ios.skip(5); // ios.writeBytes("Hello");
n = ios.skip(6); // ios.writeChars("ABC");
ios.readFully(b); // reads up to b.length bytes of data into an array of bytes
ios.readFully(b, 2, 1); // reads up to len bytes of data into an array of bytes
i = ios.readUnsignedByte(); // reads ubyte (1 byte)
i = ios.readUnsignedShort(); // reads ushort (2 bytes)
n = ios.skip(1); // skips over and discards n bytes of data from the input stream
n = ios.skipBytes(1); // skips over and discards n bytes of data from the input stream
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
/*********************************************************************
* *
* PushbackInputStream: (extends FilterInputStream) *
* *
* Desc: Adds ability to push back single byte *
* *
* Methods: *
* available read unread *
* markSupported *
* *
*********************************************************************/
void pushbackinputstream() {
int i;
long n;
byte[] b = new byte[4];
try {
PushbackInputStream ios =
new PushbackInputStream(new ChrisInputStream("io/FileOutputStream.txt"), 4096);
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
i = ios.available(); // number of bytes that can be read from this file without blocking
i = ios.read(); // reads a byte of data
ios.unread(i+10); // push back a byte
i = ios.read();
i = ios.read(b); // reads up to b.length bytes of data into an array of bytes
ios.unread(b); // push back an array of bytes
i = ios.read(b);
i = ios.read(b, 2, 1); // reads up to len bytes of data into an array of bytes
ios.unread(b, 2, 1); // push back a portion of an array of bytes
i = ios.read(b, 2, 1);
n = ios.skip(1); // Skips over and discards n bytes of data from the input stream
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
/*********************************************************************
* *
* LineNumberInputStream: (extends FilterInputStream) *
* *
* Desc: Keeps track of number of input lines read - deprecated*
* *
* Methods: *
* available read skip *
* getLineNumber reset *
* mark setLineNumber *
* *
*********************************************************************/
void linenumberinputstream() {
/* This class has been deprecated - use PrintWriter instead
int i;
long n;
byte[] b = new byte[4];
try {
LineNumberInputStream ios =
new LineNumberInputStream(new ChrisInputStream("io/FileOutputStream.txt"));
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
i = ios.available(); // number of bytes that can be read from this file without blocking
i = ios.read(); // reads a byte of data
i = ios.read(b); // reads up to b.length bytes of data into an array of bytes
i = ios.read(b, 2, 1); // reads up to len bytes of data into an array of bytes
n = ios.skip(1); // Skips over and discards n bytes of data from the input stream
i = ios.getLineNumber(); // returns the current line number
ios.setLineNumber(100); // sets the line number
i = ios.getLineNumber();
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
*/
}
/*********************************************************************
* *
* SequenceInputStream: (extends InputStream) *
* *
* Desc: Combine multiple input streams into single stream *
* *
* Methods: *
* available close read *
* *
*********************************************************************/
void sequenceinputstream() {
int i;
long n;
byte[] b = new byte[4];
try {
ChrisInputStream xa = new ChrisInputStream("io/OutputStream.txt");
ChrisInputStream xb = new ChrisInputStream("io/BufferedOutputStream.txt");
SequenceInputStream ios = new SequenceInputStream(xa, xb);
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
i = ios.available(); // number of bytes that can be read from this file without blocking
i = ios.read(); // reads a byte of data
i = ios.read(b); // reads up to b.length bytes of data into array of bytes - inherited
i = ios.read(b, 2, 1); // reads up to len bytes of data into an array of bytes
n = ios.skip(1); // Skips over and discards n bytes of data from the input stream
i = ios.read();
i = ios.read(b);
i = ios.read(b, 2, 1);
n = ios.skip(1);
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
/*********************************************************************
* *
* StringBufferInputStream: (extends InputStream) *
* *
* Desc: Inputs StringBuffer to a byte stream - deprecated *
* *
* Methods: *
* available reset skip *
* read *
* *
*********************************************************************/
void stringbufferinputstream() {
/* This class has been deprecated - use PrintWriter instead
int i;
long n;
byte[] b = new byte[4];
try {
StringBufferInputStream ios = new StringBufferInputStream("abcdefg");
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
i = ios.available(); // number of bytes that can be read from this file without blocking
i = ios.read(); // reads a byte of data
i = ios.read(b); // reads up to b.length bytes of data into an array of bytes
i = ios.read(b, 2, 1); // reads up to len bytes of data into an array of bytes
n = ios.skip(1); // Skips over and discards n bytes of data from the input stream
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
*/
}
/*********************************************************************
* *
* Reader: (abstract) *
* *
* Desc: Base abstract class for reading characters *
* *
* Methods: *
* close read skip *
* mark ready *
* markSupported reset *
* *
*********************************************************************/
class ChrisReader extends Reader {
/*
*
* Derived Subclasses:
*
* InputStreamReader
* Filereader
* CharArrayReader
* StringReader
* PipedReader
* PrintReader
* BufferedReader
* FilterReader
*
*/
DataInputStream xf;
public ChrisReader(String s) throws IOException {
xf = new DataInputStream(new FileInputStream(s));
}
public int read() throws IOException {
return xf.readChar();
}
public int read(char[] b) throws IOException {
int i;
for (i = 0; i < b.length; i++) {
b[i] = xf.readChar();
if (b[i] == -1) return i;
}
return i;
}
public int read(char b[], int off, int len) throws IOException {
int i;
for (i = off; i < (off+len); i++) {
b[i] = xf.readChar();
if (b[i] == -1) return i - off;
}
return i - off;
}
public long skip(long n) throws IOException {
long i;
for (i = 0; i < n*2; i++) {
if (read() == -1) return i/2;
}
return i/2;
}
public boolean ready() throws IOException {
return false;
}
public boolean markSupported() {
return xf.markSupported();
}
public synchronized void mark(int readlimit) {
xf.mark(readlimit);
}
public synchronized void reset() throws IOException {
xf.reset();
}
public void close() throws IOException {
xf.close();
}
}
void reader() {
int i;
long n;
boolean f;
char[] c = new char[5];
try {
ChrisReader ios = new ChrisReader("io/Writer.txt");
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
f = ios.ready(); // test if stream is ready to be read
i = ios.read(); // reads a char of data
i = ios.read(); // reads a char of data
i = ios.read(c, 2, 1); // reads up to len chars of data into an array of chars
i = ios.read(c); // reads up to b.length chars of data into an array of charss
n = ios.skip(1); // skips over and discards n chars of data from the input stream
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
/*********************************************************************
* *
* InputStreamReader: (extends Reader) *
* *
* Desc: Enables reading char stream from byte stream *
* *
* Methods: *
* close read ready *
* getEncoding *
* *
*********************************************************************/
void inputstreamreader() {
int i;
long n;
boolean f;
String s;
char[] c = new char[5];
try {
InputStreamReader ios = new InputStreamReader(new FileInputStream("io/OutputStreamWriter.txt"));
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
s = ios.getEncoding(); // name of encoding used by this stream
f = ios.ready(); // test if stream is ready to be read
i = ios.read(); // reads a char of data
i = ios.read(); // reads a char of data
i = ios.read(c, 2, 1); // reads up to len chars of data into an array of chars
i = ios.read(c); // reads up to b.length chars of data into an array of chars
n = ios.skip(1); // skips over and discards n chars of data from the input stream
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
/*********************************************************************
* *
* FileReader: (extends InputStreamReader) *
* *
* Desc: Reads char stream from file *
* *
*********************************************************************/
void filereader() {
int i;
long n;
boolean f;
String s;
char[] c = new char[5];
try {
FileReader ios = new FileReader("io/OutputStreamWriter.txt");
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
s = ios.getEncoding(); // name of encoding used by this stream
f = ios.ready(); // test if stream is ready to be read
i = ios.read(); // reads a char of data
i = ios.read(); // reads a char of data
i = ios.read(c); // reads up to b.length chars of data into an array of chars
i = ios.read(c, 2, 1); // reads up to len chars of data into an array of chars
n = ios.skip(1); // skips over and discards n chars of data from the input stream
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
/*********************************************************************
* *
* CharArrayReader: (extends Reader) *
* *
* Desc: Reads character array from character stream *
* *
* Methods: *
* close read skip *
* mark ready *
* markSupported reset *
* *
*********************************************************************/
void chararrayreader() {
int i;
long n;
boolean f;
char[] b = new char[4];
char[] c = {'a', 'b', 'c', 'd', 'e', 'f', 'g'};
CharArrayReader ios = new CharArrayReader(c);
try {
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
f = ios.ready(); // test if stream is ready to be read
i = ios.read(); // reads a char of data
i = ios.read(b); // reads up to b.length chars of data into an array of chars
i = ios.read(b, 2, 1); // reads up to len chars of data into an array of chars
n = ios.skip(1); // skips over and discards n chars of data from the input stream
ios.close(); // closes input stream and releases system resources
} catch(IOException e) { System.out.println(e);
}
}
/*********************************************************************
* *
* StringReader: (extends Reader) *
* *
* Desc: Reads string from character stream *
* *
* Methods: *
* close read skip *
* mark ready *
* markSupported reset *
* *
*********************************************************************/
void stringreader() {
int i;
long n;
boolean f;
char[] b = new char[4];
StringReader ios = new StringReader("abcdefg");
try {
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
f = ios.ready(); // test if stream is ready to be read
i = ios.read(); // reads a char of data
i = ios.read(b); // reads up to b.length chars of data into an array of chars
i = ios.read(b, 2, 1); // reads up to len chars of data into an array of chars
n = ios.skip(1); // skips over and discards n chars of data from the input stream
ios.close(); // closes input stream and releases system resources
} catch(IOException e) { System.out.println(e);
}
}
/*********************************************************************
* *
* PipedReader: (extends Reader) *
* *
* Desc: Defines a char input stream from Pipe *
* *
* Methods: *
* close connect read *
* *
*********************************************************************/
void pipedreader() {
int i;
char[] b = new char[4];
char[] c = {'A', 'B', 'C', 'D', 'E', 'F', 'G'};
PipedWriter xs = new PipedWriter();
PipedReader ios = new PipedReader();
try {
ios.connect(xs); // Connects this piped input stream to a sender
xs.write(c);
if (ios.markSupported()) { } // tests if this input stream supports the mark and reset methods
i = ios.read(); // reads a char of data
i = ios.read(b); // reads up to b.length chars of data into an array of chars
i = ios.read(b, 2, 1); // reads up to len chars of data into an array of chars
// bug warning: no offset applied to read!!!
ios.close(); // closes input stream and releases system resources
} catch (IOException e) {
}
}
/*********************************************************************
* *
* FilterReader: (abstract) (extends Reader) *
* *
* Desc: Base class to extend other reader streams *
* *
* Methods: *
* close read skip *
* mark ready *
* markSupported reset *
* *
*********************************************************************/
class ChrisFilterReader extends FilterReader {
ChrisFilterReader(Reader ios) {
super(ios); // constructor is protected for this class
}
}
void filterreader() {
/*
*
* This class usually acts as an intermediate layer between InputStream and
* the derived subclasses:
*
* PushbackReader
*
*/
int i;
long n;
boolean f;
char[] c = new char[5];
try {
ChrisFilterReader ios = new ChrisFilterReader(new FileReader("io/OutputStreamWriter.txt"));
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
f = ios.ready(); // test if stream is ready to be read
i = ios.read(); // reads a char of data
i = ios.read(); // reads a char of data
i = ios.read(c); // reads up to b.length chars of data into an array of chars
i = ios.read(c, 2, 1); // reads up to len chars of data into an array of chars
n = ios.skip(1); // skips over and discards n chars of data from the input stream
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
/*********************************************************************
* *
* PushbackReader: (extends FilterReader) *
* *
* Desc: Adds ability to push back single character *
* *
* Methods: *
* close read unread *
* markSupported ready *
* *
*********************************************************************/
void pushbackreader() {
int i;
long n;
boolean f;
char[] c = new char[5];
try {
PushbackReader ios = new PushbackReader(new FileReader("io/OutputStreamWriter.txt"), 4096);
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
f = ios.ready(); // test if stream is ready to be read
i = ios.read(); // reads a char of data
ios.unread(i+10); // push back a char
i = ios.read();
i = ios.read(); // reads a char of data
i = ios.read(c); // reads up to b.length chars of data into an array of chars
ios.unread(c); // push back an array of chars
i = ios.read(c);
i = ios.read(c, 2, 1); // reads up to len chars of data into an array of chars
ios.unread(c, 2, 1); // push back a portion of an array of chars
i = ios.read(c, 2, 1);
n = ios.skip(1); // skips over and discards n chars of data from the input stream
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
/*********************************************************************
* *
* BufferedReader: (extends Reader) *
* *
* Desc: Adds buffering to a char input stream *
* *
* Methods: *
* close read reset *
* mark readLine skip *
* markSupported ready *
* *
*********************************************************************/
void bufferedreader() {
int i;
long n;
boolean f;
String s;
char[] c = new char[5];
try {
BufferedReader ios = new BufferedReader(new FileReader("io/OutputStreamWriter.txt"), 4096);
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
f = ios.ready(); // test if stream is ready to be read
i = ios.read(); // reads a char of data
i = ios.read(); // reads a char of data
i = ios.read(c); // reads up to b.length chars of data into an array of chars
i = ios.read(c, 2, 1); // reads up to len chars of data into an array of chars
n = ios.skip(1); // skips over and discards n chars of data from the input stream
s = ios.readLine(); // read a line of text
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
/*********************************************************************
* *
* LineNumberReader: (extends BufferedReader) *
* *
* Desc: Keeps track of number of input lines read *
* *
* Methods: *
* getLineNumber readLine skip *
* mark reset *
* read setLineNumber *
* *
*********************************************************************/
void linenumberreader() {
int i;
long n;
boolean f;
String s;
char[] c = new char[5];
try {
LineNumberReader ios = new LineNumberReader(new FileReader("io/OutputStreamWriter.txt"), 4096);
if (ios.markSupported()) { // tests if this input stream supports the mark and reset methods
ios.mark(10); // marks the current position in this input stream
i = ios.read();
ios.reset(); // repositions to last mark position
}
f = ios.ready(); // test if stream is ready to be read
i = ios.read(); // reads a char of data
i = ios.read(); // reads a char of data
i = ios.read(c); // reads up to b.length chars of data into an array of chars
i = ios.read(c, 2, 1); // reads up to len chars of data into an array of chars
n = ios.skip(1); // skips over and discards n chars of data from the input stream
s = ios.readLine(); // read a line of text
i = ios.getLineNumber(); // returns the current line number
ios.setLineNumber(100); // sets the line number
i = ios.getLineNumber();
ios.close(); // closes input stream and releases system resources
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
/*********************************************************************
* *
* RandomAccessFile: *
* *
* Methods: *
* close readInt writeByte *
* getFD readLine writeBytes *
* getFilePointer readLong writeChar *
* length readShort writeChars *
* read readUnsignedByte writeDouble *
* readBoolean readUnsignedShort writeFloat *
* readByte readUTF writeInt *
* readChar seek writeLong *
* readDouble skipBytes writeShort *
* readFloat write writeUTF *
* readFully writeBoolean *
* *
*********************************************************************/
void randomaccessfile() {
boolean f;
char c;
int i;
short j;
long n;
float x;
double y;
String s;
FileDescriptor fd;
byte[] b = {0x31, 0x32, 0x33, 0x34};
// all data is written as stream of bytes to the OutputStream
try {
File xf = new File("RandomAccessFile.txt");
xf.delete();
RandomAccessFile ios = new RandomAccessFile("io/RandomAccessFile.txt", "rw");
fd = ios.getFD(); // returns the file descriptor associated with this stream
ios.write(0x30); // writes the specified byte to output stream
ios.write(b);
ios.write(b, 2, 1);
ios.writeBoolean(true); // writes boolean (1 byte)
ios.writeByte(0x30); // writes byte (1 byte)
ios.writeChar('A'); // writes char (2 bytes)
ios.writeShort(567); // writes short (2 bytes)
ios.writeInt(1234); // writes int (4 bytes)
ios.writeLong(4321L); // writes long (8 bytes)
ios.writeFloat(3.21f); // writes float (4 bytes)
ios.writeDouble(1.23); // writes double (8 bytes)
ios.writeUTF("Fred"); // writes UTF-8 encoded string
ios.writeBytes("Hello"); // writes string (1 byte per char)
ios.writeChars("ABC"); // writes string (2 bytes per char)
ios.write(b);
ios.write(b, 2, 1);
ios.writeByte(0x35);
ios.writeShort(765);
ios.write(0x39);
n = ios.length(); // returns length of file
n = ios.getFilePointer(); // returns current offset in file
ios.seek(0); // sets offset from BOF at which the next read or write occurs
i = ios.read(); // reads a byte of data
i = ios.read(b); // reads up to b.length bytes of data into an array of bytes
i = ios.read(b, 2, 1); // reads up to len bytes of data into an array of bytes
f = ios.readBoolean(); // reads boolean (1 byte)
b[0] = ios.readByte(); // reads byte (1 byte)
c = ios.readChar(); // reads char (2 bytes)
j = ios.readShort(); // reads short (2 bytes)
i = ios.readInt(); // reads int (4 bytes)
n = ios.readLong(); // reads long (8 bytes)
x = ios.readFloat(); // reads float (4 bytes)
y = ios.readDouble(); // reads double (8 bytes)
s = ios.readUTF(); // reads UTF-8 encoded string
n = ios.skipBytes(5); // ios.writeBytes("Hello");
n = ios.skipBytes(6); // ios.writeChars("ABC");
ios.readFully(b); // reads up to b.length bytes of data into an array of bytes
ios.readFully(b, 2, 1); // reads up to len bytes of data into an array of bytes
i = ios.readUnsignedByte(); // reads ubyte (1 byte)
i = ios.readUnsignedShort(); // reads ushort (2 bytes) - converts to int
n = ios.skipBytes(1); // skips over and discards n bytes of data from the input stream
ios.close(); // closes i/o stream and releases system resources
} catch(IOException e) { System.out.println(e);
}
}
/*********************************************************************
* *
* ObjectOutputStream: (extends OutputStream) *
* *
* Methods: *
* annotateClass write writeInt *
* close writeBoolean writeLong *
* defaultWriteObject writeByte writeObject *
* drain writeBytes writeShort *
* enableReplaceObject writeChar writeStreamHeader *
* flush writeChars writeUTF *
* replaceObject writeDouble *
* reset writeFloat *
* *
*********************************************************************/
void objectoutputstream() {
byte[] b = {0x31, 0x32, 0x33, 0x34};
Java_io_Serializable obj = new Java_io_Serializable();
try {
ObjectOutputStream ios = new ObjectOutputStream(new ChrisOutputStream("io/ObjectOutputStream.txt"));
ios.writeObject(obj); // write object - serialize
ios.write(0x30); // writes the specified char to output stream
ios.write(b);
ios.write(b, 2, 1);
ios.writeBoolean(true); // writes boolean (1 byte)
ios.writeByte(0x30); // writes byte (1 byte)
ios.writeChar('A'); // writes char (2 bytes)
ios.writeShort(567); // writes short (2 bytes)
ios.writeInt(1234); // writes int (4 bytes)
ios.writeLong(4321L); // writes long (8 bytes)
ios.writeFloat(3.21f); // writes float (4 bytes)
ios.writeDouble(1.23); // writes double (8 bytes)
ios.writeUTF("Fred"); // writes UTF-8 encoded string
ios.writeBytes("Hello"); // writes string (1 byte per char)
ios.writeChars("ABC"); // writes string (2 bytes per char)
ios.write(b);
ios.write(b, 2, 1);
ios.writeByte(0x35);
ios.writeShort(765);
ios.write(0x38);
ios.write(0x39);
ios.flush(); // forces any buffered output bytes to be written out
ios.close(); // closes output stream and releases system resources
} catch(InvalidClassException e) { System.out.println(e);
System.out.println(e);
} catch(NotSerializableException e) { System.out.println(e);
System.out.println(e);
} catch(IOException e) { System.out.println(e);
System.out.println(e);
}
/* TO BE DETERMINED
annotateClass(Class) // allow class data to be stored
defaultWriteObject() // write non-static and non-transient fields of current class
drain() // drain any buffered data
enableReplaceObject(boolean) // Enable the stream to do replacement of objects in the stream
replaceObject(Object) // allow trusted subclasses to substitute object during serialization
reset() // disregard the state of any objects already written
writeStreamHeader() // allow subclasses to append or prepend their own header
*/
}
/*********************************************************************
* *
* ObjectInputStream: *
* *
* Methods: *
* available readDouble readStreamHeader *
* close readFloat readUnsignedByte *
* defaultReadObject readFully readUnsignedShort *
* enableResolveObject readInt readUTF *
* read readLine registerValidation*
* readBoolean readLong resolveClass *
* readByte readObject resolveObject *
* readChar readShort skipBytes *
* *
*********************************************************************/
void objectinputstream() {
boolean f;
char c;
int i;
short j;
long n;
float x;
double y;
String s;
byte[] b = new byte[4];
Java_io_Serializable obj;
try {
ObjectInputStream ios = new ObjectInputStream(new FileInputStream("io/ObjectOutputStream.txt"));
obj = (Java_io_Serializable)ios.readObject(); // read object - deserialize
if (ios.markSupported()) { } // tests if this input stream supports the mark and reset methods
i = ios.available(); // number of bytes that can be read from this file without blocking
i = ios.read(); // reads a byte of data
i = ios.read(b); // reads up to b.length bytes of data into an array of bytes
i = ios.read(b, 2, 1); // reads up to len bytes of data into an array of bytes
f = ios.readBoolean(); // reads boolean (1 byte)
b[0] = ios.readByte(); // reads byte (1 byte)
c = ios.readChar(); // reads char (2 bytes)
j = ios.readShort(); // reads short (2 bytes)
i = ios.readInt(); // reads int (4 bytes)
n = ios.readLong(); // reads long (8 bytes)
x = ios.readFloat(); // reads float (4 bytes)
y = ios.readDouble(); // reads double (8 bytes)
s = ios.readUTF(); // reads UTF-8 encoded string
n = ios.skip(5); // ios.writeBytes("Hello");
n = ios.skip(6); // ios.writeChars("ABC");
ios.readFully(b); // reads up to b.length bytes of data into an array of bytes
ios.readFully(b, 2, 1); // reads up to len bytes of data into an array of bytes
i = ios.readUnsignedByte(); // reads ubyte (1 byte)
i = ios.readUnsignedShort(); // reads ushort (2 bytes)
n = ios.skip(1); // skips over and discards n bytes of data from the input stream
n = ios.skipBytes(1); // skips over and discards n bytes of data from the input stream
ios.close(); // closes input stream and releases system resources
} catch(ClassNotFoundException e) { System.out.println(e);
System.out.println(e);
} catch(InvalidClassException e) { System.out.println(e);
System.out.println(e);
} catch(StreamCorruptedException e) { System.out.println(e);
System.out.println(e);
} catch(OptionalDataException e) { System.out.println(e);
System.out.println(e);
} catch(IOException e) { System.out.println(e);
System.out.println(e);
}
/* TO BE DETERMINED
defaultReadObject() // Read non-static and non-transient fields of current class
enableResolveObject(boolean) // allow objects read from the stream to be replaced
readLine() // Reads in a line terminated by a \n, \r, \r\n or EOF
readStreamHeader() // allow subclasses to read and verify their own stream headers
registerValidation(ObjectInputValidation, int) // Register object before the graph is returned
resolveClass(ObjectStreamClass) // allow classes to be fetched from an alternate source
resolveObject(Object) // allow trusted subclasses to substitute object during deserialization
*/
}
/*********************************************************************
* *
* ObjectStreamClass: *
* *
* Methods: *
* forClass getSerialVersionUID toString *
* getName lookup *
* *
*********************************************************************/
void objectstreamclass() {
/* TO BE DETERMINED
forClass() // Return the class in the local VM that this version is mapped to
getName() // The name of the class described by this descriptor
getSerialVersionUID() // Return the serialVersionUID for this class
lookup(Class) // Find the descriptor for a class that can be serialized
toString() // Return a string describing this ObjectStreamClass
*/
}
/*********************************************************************
* *
* FileDescriptor: *
* *
* err in out *
* *
* Methods: *
* sync valid *
* *
*********************************************************************/
void filedescriptor() {
/* TO BE DETERMINED
err // A handle to the standard error stream
in // A handle to the standard input stream
out // A handle to the standard output stream
sync() // Force all system buffers to synchronize with the underlying device
valid() // Tests if this file descriptor object is valid
*/
}
/*********************************************************************
* *
* StreamTokenizer: *
* *
* nval TT_EOL ttype *
* sval TT_NUMBER *
* TT_EOF TT_WORD *
* *
* Methods: *
* commentChar ordinaryChars slashStarComments *
* eolIsSignificant parseNumbers toString *
* lineno pushBack whitespaceChars *
* lowerCaseMode quoteChar wordChars *
* nextToken resetSyntax *
* ordinaryChar slashSlashComments *
* *
*********************************************************************/
void streamtokenizer() {
/* TO BE DETERMINED
nval // If the current token is a number, this field contains the value of that number
sval // If the current token is a word token, this field contains a string giving the characters of the word token
TT_EOF // A constant indicating that the end of the stream has been read
TT_EOL // A constant indicating that the end of the line has been read
TT_NUMBER // A constant indicating that a number token has been read
TT_WORD // A constant indicating that a word token has been read
ttype // After a call to the nextToken method, this field contains the type of the token just read
commentChar(int) // Specified that the character argument starts a single-line comment
eolIsSignificant(boolean) // Determines whether or not ends of line are treated as tokens
lineno() // Return the current line number
lowerCaseMode(boolean) // Determines whether or not word token are automatically lowercased
nextToken() // Parses the next token from the input stream of this tokenizer
ordinaryChar(int) // Specifies that the character argument is "ordinary" in this tokenizer
ordinaryChars(int, int) // Specifies that all characters c in the range low <= c <= high are "ordinary" in this tokenizer
parseNumbers() // Specifies that numbers should be parsed by this tokenizer
pushBack() // Causes the next call to the nextToken method of this tokenizer to return the current value in the ttype field, and not to modify the value in the nval or sval field
quoteChar(int) // Specifies that matching pairs of this character delimit string constants in this tokenizer
resetSyntax() // Resets this tokenizer's syntax table so that all characters are "ordinary." See the ordinaryChar method for more information on a character being ordinary
slashSlashComments(boolean) // Determines whether or not the tokenizer recognizes C++-style comments
slashStarComments(boolean) // Determines whether or not the tokenizer recognizes C-style comments
toString() // Returns the string representation of the current stream token
whitespaceChars(int, int) // Specifies that all characters c in the range low <= c <= high are white space characters
wordChars(int, int) // Specifies that all characters c in the range low <= c <= high are word constituents
*/
}
/*********************************************************************
* *
* DataInput Interface: *
* *
* Methods: *
* readChar readInt readUnsignedByte *
* readDouble readLine readUnsignedShort *
* readFloat readLong readUTF *
* readFully readShort skipBytes *
* *
*********************************************************************/
void datainput() {
/* TO BE DETERMINED
readChar() // Reads a Unicode char value from the input stream
readDouble() // Reads a double value from the input stream
readFloat() // Reads a float value from the input stream
readFully(byte[]) // Reads b.length bytes into the byte array
readFully(byte[], int, int) // Reads b.length bytes into the byte array
readInt() // Reads an int value from the input stream
readLine() // Reads the next line of text from the input stream
readLong() // Reads a long value from the input stream
readShort() // Reads a 16-bit value from the input stream
readUnsignedByte() // Reads an unsigned 8-bit value from the input stream
readUnsignedShort() // Reads an unsigned 16-bit value from the input stream
readUTF() // Reads in a string that has been encoded using a modified UTF-8 format
skipBytes(int) // Skips eiosctly n bytes of input
*/
}
/*********************************************************************
* *
* DataOutput Interface: *
* *
* Methods: *
* write writeChar writeInt *
* writeBoolean writeChars writeLong *
* writeByte writeDouble writeShort *
* writeBytes writeFloat writeUTF *
* *
*********************************************************************/
void dataoutput() {
/* TO BE DETERMINED
write(byte[]) // Writes b.length bytes from the specified byte array to this output stream
write(byte[], int, int) // Writes len bytes from the specified byte array starting at offset off to this output stream
write(int) // Writes the specified byte to this data output stream
writeBoolean(boolean) // Writes a boolean value to this output stream
writeByte(int) // Writes an 8-bit value to this output stream
writeBytes(String) // Writes a string to this output stream
writeChar(int) // Writes a char value to this output stream
writeChars(String) // Writes a string to this output stream
writeDouble(double) // Writes a double value to this output stream
writeFloat(float) // Writes a float value to this output stream
writeInt(int) // Writes an int value to this output stream
writeLong(long) // Writes a long value to this output stream
writeShort(int) // Writes a 16-bit value to this output stream
writeUTF(String) // Writes a Unicode string by encoding it using modified UTF-8 format
*/
}
/*********************************************************************
* *
* Externalizable Interface: *
* *
* Methods: *
* readExternal writeExternal *
* *
*********************************************************************/
void externalizable() {
/* TO BE DETERMINED
readExternal(ObjectInput) // The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays
writeExternal(ObjectOutput) // The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings and arrays
*/
}
/*********************************************************************
* *
* ObjectInput Interface: *
* *
* Methods: *
* available read skip *
* close readObject *
* *
*********************************************************************/
void objectinput() {
/* TO BE DETERMINED
available() // Returns the number of bytes that can be read without blocking
close() // Closes the input stream
read() // Reads a byte of data
read(byte[]) // Reads into an array of bytes
read(byte[], int, int) // Reads into an array of bytes
readObject() // Read and return an object
skip(long) // Skips n bytes of input
*/
}
/*********************************************************************
* *
* ObjectInputValidation Interface: *
* *
* Methods: *
* validateObject *
* *
*********************************************************************/
void objectinputvalidation() {
/* TO BE DETERMINED
validateObject() // Validates the object
*/
}
/*********************************************************************
* *
* ObjectOutput Interface: *
* *
* Methods: *
* close write writeObject *
* flush *
* *
*********************************************************************/
void objectoutput() {
/* TO BE DETERMINED
close() // Closes the stream
flush() // Flushes the stream
write(byte[]) // Writes an array of bytes
write(byte[], int, int) // Writes a sub array of bytes
write(int) // Writes a byte
writeObject(Object) // Write an object to the underlying storage or stream
*/
}
}