net.sf.hermesftp.streams
Class RecordOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by net.sf.hermesftp.streams.RecordOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, RecordWriteSupport

public class RecordOutputStream
extends java.io.OutputStream
implements RecordWriteSupport

In a record structured file EOR and EOF will each be indicated by a two-byte control code. The first byte of the control code will be all ones, the escape character. The second byte will have the low order bit on and zeros elsewhere for EOR and the second low order bit on for EOF; that is, the byte will have value 1 for EOR and value 2 for EOF. EOR and EOF may be indicated together on the last byte transmitted by turning both low order bits on (i.e., the value 3). If a byte of all ones was intended to be sent as data, it should be repeated in the second byte of the control code.

Author:
Lars Behnke

Constructor Summary
RecordOutputStream(java.io.OutputStream os)
          Constructor.
 
Method Summary
 void close()
          Before the stream is closed and EOF marker is set.
 void finalizeRecord(boolean eof)
          Flushes the buffer and sets an EOR / EOF marker.
 void flush()
          A flush ends the current record.
 void write(int b)
          
 void writeRecord(byte[] record, boolean eof)
          Writes a whole record and sets the end marker.
 
Methods inherited from class java.io.OutputStream
write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RecordOutputStream

public RecordOutputStream(java.io.OutputStream os)
Constructor.

Parameters:
os - The output stream.
Method Detail

writeRecord

public void writeRecord(byte[] record,
                        boolean eof)
                 throws java.io.IOException
Writes a whole record and sets the end marker.

Specified by:
writeRecord in interface RecordWriteSupport
Parameters:
record - The record to transmit.
eof - End of file is reached.
Throws:
java.io.IOException - Thrown if somethings goes wrong.

write

public void write(int b)
           throws java.io.IOException

Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
A flush ends the current record. Flushes any buffered record data.

Specified by:
flush in interface java.io.Flushable
Specified by:
flush in interface RecordWriteSupport
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException - Thrown if IO fails.

finalizeRecord

public void finalizeRecord(boolean eof)
                    throws java.io.IOException
Flushes the buffer and sets an EOR / EOF marker.

Parameters:
eof - True if end of file.
Throws:
java.io.IOException - thrown if writing to stream fails.

close

public void close()
           throws java.io.IOException
Before the stream is closed and EOF marker is set.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException


Copyright © 2005-2007 Lars Behnke. All Rights Reserved.