Author: saqibkhan

  • OutputStreamWriter 

    Introduction

    The Java.io.OutputStreamWriter class is a bridge from character streams to byte streams. Characters written to it are encoded into bytes using a specified charset.

    Class declaration

    Following is the declaration for Java.io.OutputStreamWriter class −

    public class OutputStreamWriter
       extends Writer
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.OutputStreamWriter class −

    • protected Object lock − This is the object used to synchronize operations on this stream.

    Class constructors

    Sr.No.Constructor & Description
    1OutputStreamWriter(OutputStream out)This creates an OutputStreamWriter that uses the default character encoding.
    2OutputStreamWriter(OutputStream out, Charset cs)This creates an OutputStreamWriter that uses the given charset.
    3OutputStreamWriter(OutputStream out, CharsetEncoder enc)This creates an OutputStreamWriter that uses the given charset encoder.
    4OutputStreamWriter(OutputStream out, String charsetName)This creates an OutputStreamWriter that uses the named charset.

    Class methods

    Sr.No.Method & Description
    1void close()This method closes the stream, flushing it first.
    2void flush()This method flushes the stream.
    3String getEncoding()This method returns the name of the character encoding being used by this stream.
    4void write(char[] cbuf, int off, int len)This method writes a portion of an array of characters.
    5void write(int c)This method writes a single character.
    6void write(String str, int off, int len)This method writes a portion of a string.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Writer
    • Java.io.Object
  • OutputStream 

    Introduction

    The Java.io.OutputStream class is the superclass of all classes representing an output stream of bytes. An output stream accepts output bytes and sends them to some sink.Applications that need to define a subclass of OutputStream must always provide at least a method that writes one byte of output.

    Class declaration

    Following is the declaration for Java.io.OutputStream class −

    public abstract class OutputStream
       extends Object
    
      implements Closeable, Flushable

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class constructors

    Sr.No.Constructor & Description
    1OutputStream()Single Constructor.

    Class methods

    Sr.No.Method & Description
    1void close()This method closes this output stream and releases any system resources associated with this stream.
    2void flush()This method flushes this output stream and forces any buffered output bytes to be written out.
    3void write(byte[] b)This method writes b.length bytes from the specified byte array to this output stream.
    4void write(byte[] b, int off, int len)This method writes len bytes from the specified byte array starting at offset off to this output stream.
    5abstract void write(int b)This method writes the specified byte to this output stream.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Object
  • ObjectStreamField 

    Introduction

    The Java.io.ObjectStreamField class is a description of a Serializable field from a Serializable class. An array of ObjectStreamFields is used to declare the Serializable fields of a class.

    Class declaration

    Following is the declaration for Java.io.ObjectStreamField class −

    public class ObjectStreamField
       extends Object
    
      implements Comparable<Object>

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class constructors

    Sr.No.Constructor & Description
    1ObjectStreamField(String name, Class<?> type)This creates a Serializable field with the specified type.
    2ObjectStreamField(String name, Class<?> type, boolean unshared)This creates an ObjectStreamField representing a serializable field with the given name and type.

    Class methods

    Sr.No.Method & Description
    1int compareTo(Object obj)This method compares this field with another ObjectStreamField.
    2String getName()This method gets the name of this field.
    3int getOffset()This method returns the offset of field within instance data.
    4Class<?> getType()This method gets the type of the field.
    5char getTypeCode()This method returns character encoding of field type.
    6String getTypeString()This method returns the JVM type signature.
    7boolean isPrimitive()This method returns true if this field has a primitive type.
    8boolean isUnshared()This method returns boolean value indicating whether or not the serializable field represented by this ObjectStreamField instance is unshared.
    9protected void setOffset(int offset)This method returns offset within instance data.
    10String toString()This method returns a string that describes this field.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Object
  • ObjectStreamClass 

    Introduction

    The Java.io.ObjectStreamClass class is Serialization’s descriptor for classes. It contains the name and serialVersionUID of the class. The ObjectStreamClass for a specific class loaded in this Java VM can be found/created using the lookup method.

    Class declaration

    Following is the declaration for Java.io.ObjectStreamClass class −

    public class ObjectStreamClass
       extends Object
    
      implements Serializable

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.ObjectStreamClass class −

    • static ObjectStreamField[] NO_FIELDS − This is the serialPersistentFields value indicating no serializable fields.

    Class methods

    Sr.No.Method & Description
    1Class<?> forClass()This method returns the class in the local VM that this version is mapped to.
    2ObjectStreamField getField(String name)This method gets the field of this class by name.
    3ObjectStreamField[] getFields()This method returns an array of the fields of this serializable class.
    4String getName()This method returns the name of the class described by this descriptor.
    5long getSerialVersionUID()This method returns the serialVersionUID for this class.
    6static ObjectStreamClass lookup(Class<?> cl)This method finds the descriptor for a class that can be serialized.
    7static ObjectStreamClass lookupAny(Class<?> cl)This method returns the descriptor for any class, regardless of whether it implements Serializable.
    8String toString()This method returns a string describing this ObjectStreamClass.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Object
  • ObjectOutputStream.PutField

    Introduction

    The Java.io.ObjectOutputStream.PutField class provide programmatic access to the persistent fields to be written to ObjectOutput.

    Class declaration

    Following is the declaration for Java.io.ObjectOutputStream.PutField class −

    public abstract static class ObjectOutputStream.PutField
       extends Object
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class constructors

    Sr.No.Constructor & Description
    1ObjectOutputStream.PutField()Single Constructor

    Class methods

    Sr.No.Method & Description
    1abstract void put(String name, boolean val)This method puts the value of the named boolean field into the persistent field.
    2abstract void put(String name, byte val)This method puts the value of the named byte field into the persistent field.
    3abstract void put(String name, char val)This method puts the value of the named char field into the persistent field.
    4abstract void put(String name, double val)This method puts the value of the named double field into the persistent field.
    5abstract void put(String name, float val)This method puts the value of the named float field into the persistent field.
    6abstract void put(String name, int val)This method puts the value of the named int field into the persistent field.
    7abstract void put(String name, long val)This method puts the value of the named long field into the persistent field.
    8abstract void put(String name, Object val)This method puts the value of the named Object field into the persistent field.
    9abstract void put(String name, short val)This method puts the value of the named short field into the persistent field.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Object
  • ObjectOutputStream 

    Introduction

    The Java.io.ObjectOutputStream class writes primitive data types and graphs of Java objects to an OutputStream.The objects can be read (reconstituted) using an ObjectInputStream.

    Class declaration

    Following is the declaration for Java.io.ObjectOutputStream class −

    public class ObjectOutputStream
       extends OutputStream
    
      implements ObjectOutput, ObjectStreamConstants

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class constructors

    Sr.No.Constructor & Description
    1protected ObjectOutputStream()This provides a way for subclasses that are completely reimplementing ObjectOutputStream to not have to allocate private data just used by this implementation of ObjectOutputStream.
    2ObjectOutputStream(OutputStream out)This creates an ObjectOutputStream that writes to the specified OutputStream.

    Class methods

    Sr.No.Method & Description
    1protected void annotateClass(Class <?> cl)Subclasses may implement this method to allow class data to be stored in the stream.
    2protected void annotateProxyClass(Class<?> cl)Subclasses may implement this method to store custom data in the stream along with descriptors for dynamic proxy classes.
    3void close()This method closes the stream.
    4void defaultWriteObject()This method writes the non-static and non-transient fields of the current class to this stream.
    5protected void drain()This method drain any buffered data in ObjectOutputStream.
    6protected boolean enableReplaceObject(boolean enable)This method enable the stream to do replacement of objects in the stream.
    7void flush()This method flushes the stream.
    8ObjectOutputStream.PutField putFields()This method retrieves the object used to buffer persistent fields to be written to the stream.
    9protected Object replaceObject(Object obj)This method will allow trusted subclasses of ObjectOutputStream to substitute one object for another during serialization.
    10void reset()This method reset will disregard the state of any objects already written to the stream.
    11void useProtocolVersion(int version)This method specify stream protocol version to use when writing the stream.
    12void write(byte[] buf)This method writes an array of bytes.
    13void write(byte[] buf, int off, int len)This method writes a sub array of bytes.
    14void write(int val)This method writes a byte.
    15void writeBoolean(boolean val)This method writes a boolean.
    16void writeByte(int val)This method writes an 8 bit byte.
    17void writeBytes(String str)This method writes a String as a sequence of bytes.
    18void writeChar(int val)This method writes a 16 bit char.
    19void writeChars(String str)This method writes a String as a sequence of chars.
    20protected void writeClassDescriptor(ObjectStreamClass desc)This method writes the specified class descriptor to the ObjectOutputStream.
    21void writeDouble(double val)This method writes a 64 bit double.
    22void writeFields()This method writes the buffered fields to the stream.
    23void writeFloat(float val)This method writes a 32 bit float.
    24void writeInt(int val)This method writes a 32 bit int.
    25void writeLong(long val)This method writes a 64 bit long.
    26void writeObject(Object obj)This method writes the specified object to the ObjectOutputStream.
    27protected void writeObjectOverride(Object obj)This method is used by subclasses to override the default writeObject method.
    28void writeShort(int val)This method writes a 16 bit short.
    29protected void writeStreamHeader()This method is provided so subclasses can append or prepend their own header to the stream.
    30void writeUnshared(Object obj)This method writes an “unshared” object to the ObjectOutputStream.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Object
  • ObjectInputStream.GetField

    Introduction

    The Java.io.ObjectInputStream.GetField class provide access to the persistent fields read from the input stream.

    Class declaration

    Following is the declaration for Java.io.ObjectInputStream.GetField class −

    public abstract static class ObjectInputStream.GetField
       extends Object
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class constructors

    Sr.No.Constructor & Description
    1ObjectInputStream.GetField()Single Constructor

    Class methods

    Sr.No.Method & Description
    1abstract boolean defaulted(String name)This method return true if the named field is defaulted and has no value in this stream.
    2abstract boolean get(String name, boolean val)This method gets the value of the named boolean field from the persistent field.
    3abstract byte get(String name, byte val)This method gets the value of the named byte field from the persistent field.
    4abstract char get(String name, char val)This method gets the value of the named char field from the persistent field.
    5abstract double get(String name, double val)This method gets the value of the named double field from the persistent field.
    6abstract float get(String name, float val)This method gets the value of the named float field from the persistent field.
    7abstract int get(String name, int val)This method gets the value of the named int field from the persistent field.
    8abstract long get(String name, long val)This method gets the value of the named long field from the persistent field.
    9abstract Object get(String name, Object val)This method get the value of the named Object field from the persistent field.
    10abstract short get(String name, short val)This method gets the value of the named short field from the persistent field.
    11abstract ObjectStreamClass getObjectStreamClass()This method gets the ObjectStreamClass that describes the fields in the stream.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.Object
  • ObjectInputStream 

    Introduction

    The Java.io.ObjectInputStream class deserializes primitive data and objects previously written using an ObjectOutputStream. Following are the important points about BufferedInputStream −

    • It is used to recover those objects previously serialized. It ensures that the types of all objects in the graph created from the stream match the classes present in the Java Virtual Machine.
    • Classes are loaded as required using the standard mechanisms.

    Class declaration

    Following is the declaration for Java.io.ObjectInputStream class −

    public class ObjectInputStream
       extends InputStream
    
      implements ObjectInput, ObjectStreamConstants

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Class constructors

    Sr.No.Constructor & Description
    1protected ObjectInputStream()This provide a way for subclasses that are completely reimplementing ObjectInputStream to not have to allocate private data just used by this implementation of ObjectInputStream.
    2ObjectInputStream(InputStream in)This creates an ObjectInputStream that reads from the specified InputStream.

    Class methods

    Sr.No.Method & Description
    1int available()This method returns the number of bytes that can be read without blocking.
    2void close()This method closes the input stream.
    3void defaultReadObject()This method reads the non-static and non-transient fields of the current class from this stream.
    4protected boolean enableResolveObject(boolean enable)This method enables the stream to allow objects read from the stream to be replaced.
    5int read()This method reads a byte of data.
    6int read(byte[] buf, int off, int len)This method reads into an array of bytes.
    7boolean readBoolean()This method reads in a boolean.
    8byte readByte()This method reads an 8 bit byte.
    9char readChar()This method r a 16 bit char.
    10protected ObjectStreamClass readClassDescriptor()This method read a class descriptor from the serialization stream.
    11double readDouble()This method reads a 64 bit double.
    12ObjectInputStream.GetField readFields()This method reads the persistent fields from the stream and makes them available by name.
    13float readFloat()This method reads a 32 bit float.
    14void readFully(byte[] buf)This method reads bytes, blocking until all bytes are read.
    15void readFully(byte[] buf, int off, int len)This method reads bytes, blocking until all bytes are read.
    16int readInt()This method reads a 32 bit int.
    17long readLong()This method reads a 64 bit long.
    18Object readObject()This method reads an object from the ObjectInputStream.
    19protected Object readObjectOverride()This method is called by trusted subclasses of ObjectOutputStream that constructed ObjectOutputStream using the protected no-arg constructor.
    20short readShort()This method reads a 16 bit short.
    21protected void readStreamHeader()This method is provided to allow subclasses to read and verify their own stream headers.
    22Object readUnshared()This method reads an “unshared” object from the ObjectInputStream.
    23int readUnsignedByte()This method reads an unsigned 8 bit byte.
    24int readUnsignedShort()This method reads an unsigned 16 bit short.
    25String readUTF()This method reads a String in modified UTF-8 format.
    26void registerValidation(ObjectInputValidation obj, int prio)This method register an object to be validated before the graph is returned.
    27protected Class<?> resolveClass(ObjectStreamClass desc)This method loads the local class equivalent of the specified stream class description.
    28protected Object resolveObject(Object obj)This method will allow trusted subclasses of ObjectInputStream to substitute one object for another during deserialization.
    29protected Class<?> resolveProxyClass(String[] interfaces)This method returns a proxy class that implements the interfaces named in a proxy class descriptor; subclasses may implement this method to read custom data from the stream along with the descriptors for dynamic proxy classes, allowing them to use an alternate loading mechanism for the interfaces and the proxy class.
    30int skipBytes(int len)This method skips bytes.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.InputStream
    • Java.io.Object
    • Java.io.ObjectInput
  • LineNumberReader 

    Introduction

    The Java.io.LineNumberReader class is a buffered character-input stream that keeps track of line numbers.A line is considered to be terminated by any one of a line feed (‘\n’), a carriage return (‘\r’), or a carriage return followed immediately by a linefeed.

    Class declaration

    Following is the declaration for Java.io.LineNumberReader class −

    public class LineNumberReader
       extends BufferedReader
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.LineNumberReader class −

    • protected Object lock − This is the object used to synchronize operations on this stream.

    Class constructors

    Sr.No.Constructor & Description
    1LineNumberReader(Reader in)This creates a new line-numbering reader, using the default input-buffer size.
    2LineNumberReader(Reader in, int sz)This creates a new line-numbering reader, reading characters into a buffer of the given size.

    Class methods

    Sr.No.Method & Description
    1int getLineNumber()This method gets the current line number.
    2void mark(int readAheadLimit)This method mark the present position in the stream.
    3int read()This method read a single character.
    4int read(char[] cbuf, int off, int len)This method read characters into a portion of an array.
    5String readLine()This method read a line of text.
    6void reset()This method reset the stream to the most recent mark.
    7void setLineNumber(int lineNumber)This method set the current line number.
    8long skip(long n)This method skip characters.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.BufferedReader
    • Java.io.Reader
    • Java.io.Object
  • LineNumberInputStream 

    Introduction

    The Java.io.LineNumberInputStream class is an input stream filter that provides the added functionality of keeping track of the current line number. A line is a sequence of bytes ending with a carriage return character (‘\r’), a newline character (‘\n’), or a carriage return character followed immediately by a linefeed character.

    Class declaration

    Following is the declaration for Java.io.LineNumberInputStream class −

    public class LineNumberInputStream
       extends Reader
    

    Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

    Field

    Following are the fields for Java.io.LineNumberInputStream class −

    • protected InputStream in − This is the input stream to be filtered.

    Class constructors

    Sr.No.Constructor & Description
    1LineNumberInputStream(InputStream in)This constructs a newline number input stream that reads its input from the specified input stream.

    Class methods

    Sr.No.Method & Description
    1int available()This method returns the number of bytes that can be read from this input stream without blocking.
    2int getLineNumber()This method returns the current line number.
    3void mark(int readlimit)This method marks the current position in this input stream.
    4int read()This method reads the next byte of data from this input stream.
    5int read(byte[] b, int off, int len)This method reads up to len bytes of data from this input stream into an array of bytes.
    6void reset()This method repositions this stream to the position at the time the mark method was last called on this input stream.
    7void setLineNumber(int lineNumber)This method sets the line number to the specified argument.
    8long skip(long n)This method skips over and discards n bytes of data from this input stream.

    Methods inherited

    This class inherits methods from the following classes −

    • Java.io.FilterInputStream
    • Java.io.Object