13.07.2015 Views

I/O Fundamentals

I/O Fundamentals

I/O Fundamentals

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Java Input and OutputFile Size CompressedCompressIt.java 1,330 540(AWT) Component.java 133,742 26,042Symantec JIT - symcjit.dll 419,840 193,501Java 2 SDK, version 1.2.2 - src.jar 17,288,462 3,252,177Using Object SerializationPushing Back InputSimilar to primitive value input and output, object values can be written to binaryfiles as well. Writing an object value to an output stream is known as "serializing"that object.The Java core API defines interfaces ObjectInput and ObjectOutput. Theseinterfaces define the readObject() and writeObject() methods, the core ofJava object serialization. Two classes, ObjectInputStream andObjectOutputStream implement these interfaces.Another interface, Serializable, is used to "mark" a class as one that can behandled via writeObject() and readObject(). Note that Serializable definesno methods; it is simply a "tag" to indicate that a class may be serialized.Object serialization is covered in detail in MageLang's Object Serialization coursemodule, and will not be covered further here.Sometimes you want to read all input before, but not including, a certain character.For example, you might want to read the next variable name from a stream, and thename could be terminated by a space or an operator like '+' or '-'. This becomes atricky task, as you need to read that next character (the space or '+' for example)to determine where the variable name ends. You then need to keep track of it soyou can use it as part of the next chunk being read.The Java core I/O API provides two classes, PushbackInputStream andJava Input and Output -30© 1996-2003 jGuru.com. All Rights Reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!