|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjpl.mipl.mdms.FileService.io.BufferedStreamIO
public class BufferedStreamIO
Purpose: Hides the complexity of "attaching" an output stream to an input stream for the purpose of file transfers and file transfers with message digest. This class has been revised to allow partial file transfer, which enables resume transfer in the case of network failure.
Copyright 2008, California Institute of Technology. ALL RIGHTS RESERVED. U.S. Government Sponsorship acknowledge (NASA contract NAS7-918). 2008.
============================================================================
Modification History :
----------------------
Date Who What
----------------------------------------------------------------------------
01/01/1999 MDMS Initial Release
07/08/2005 Nick Initial documentation.
Swapped "rwd" for "rw" for RandomAccFile
for server file writing.
07/15/2005 Nick Set raf.setLength() to occur after file
fully transfers to truncate, not before.
06/01/2008 Nick CRC placed in a read loop.
============================================================================
| Constructor Summary | |
|---|---|
BufferedStreamIO(BufferedInputStream bis,
BufferedOutputStream bos)
Constructor using default buffer size for buffered I/O streams. |
|
BufferedStreamIO(BufferedInputStream bis,
BufferedOutputStream bos,
int bufSize)
Constructor with specified buffer size for buffered I/O streams. |
|
BufferedStreamIO(BufferedInputStream bis,
int inBufSize,
BufferedOutputStream bos,
int outBufSize)
Constructor with specified buffer sizes for each buffered stream object. |
|
| Method Summary | |
|---|---|
byte[] |
genChecksum(byte[] buffer)
Generate a checksum on a buffer. |
byte[] |
readAndVerifyBufferFromStream(byte[] buffer,
long fileSize)
Reads from the (buffered) input stream an writes it to file. |
byte[] |
readAndVerifyFileFromStream(String fileName,
long fileSize)
Reads from the (buffered) input stream and writes it to file. |
byte[] |
readAndVerifyFileFromStream(String fileName,
long offset,
long length)
Reads from the (buffered) input stream and writes it to file with the specified offset. |
void |
readBufferFromStream(byte[] buffer,
long fileSize)
Reads from the (buffered) input stream and writes it to the specified byte buffer. |
void |
readBufferFromStream(byte[] buffer,
long fileSize,
boolean flushChecksum)
Reads from the (buffered) input stream and writes it to the specified byte buffer. |
protected byte[] |
readChecksum()
Reads the checksum from the input buffer and returns it as byte array. |
void |
readFileFromStream(OutputStream out,
long offset,
long length)
Reads a block of binary data from stream and writes to output stream. |
void |
readFileFromStream(OutputStream out,
long offset,
long length,
boolean checksum)
Reads a block of binary data from stream and writes to output stream. |
void |
readFileFromStream(String fileName,
long fileSize)
Reads from the (buffered) input stream and writes it to file |
void |
readFileFromStream(String fileName,
long offset,
long length)
Reads a block of binary data from stream and write to output file. |
String |
readLine()
Get a line from input stream |
MessagePkg |
readMessage()
Construct a message from a reply packet. |
void |
skipFile(long fileSize,
boolean doChecksum)
Method to flush an incoming file, and flush an incoming checksum, if required. |
void |
write(String s)
Write string to output stream |
byte[] |
writeAndVerifyBufferToStream(byte[] buffer,
long fileSize)
Writes a file from memory to to the (buffered) output stream A message digest will be cloned and the reference calculatedChecksum
updated. |
byte[] |
writeAndVerifyFileToStream(String fileName,
long fileSize)
Writes the input file onto buffered output stream. |
void |
writeAndVerifyFileToStream(String fileName,
long fileSize,
byte[] suppliedChecksum)
Writes the input data buffer onto buffered output stream followed by the supplied checksum value. |
byte[] |
writeAndVerifyFileToStream(String fileName,
long offset,
long length)
Writes the specified byte range within the input data file to buffered output stream and caclculates the checksum as the data is being transfered. |
void |
writeAndVerifyFileToStream(String fileName,
long offset,
long length,
byte[] suppliedChecksum)
Writes the data block within the input data file onto buffered output stream followed by the supplied checksum value. |
void |
writeFileToStream(byte[] buffer,
long fileSize)
Writes the input data buffer to buffered output stream. |
void |
writeFileToStream(String fileName,
long fileSize)
Reads a file and writes it to the (buffered) output stream. |
void |
writeFileToStream(String fileName,
long offset,
long length)
Method to read a data block from an input file and writes it to the (buffered) output stream. |
void |
writeLine(String s)
Write line to output stream |
void |
writeMessage(int errorNum,
String s)
Write a message to the command stream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BufferedStreamIO(BufferedInputStream bis,
BufferedOutputStream bos)
bis - the BufferedInputStream objectbos - the BufferedOutputStream object
public BufferedStreamIO(BufferedInputStream bis,
BufferedOutputStream bos,
int bufSize)
bis - the BufferedInputStream objectbos - the BufferedOutputStream objectbufSize - input/output buffer size in unit of bytes
public BufferedStreamIO(BufferedInputStream bis,
int inBufSize,
BufferedOutputStream bos,
int outBufSize)
bis - the BufferedInputStream objectinBufSize - input buffer size in unit of bytesbos - the BufferedOutputStream objectoutBufSize - output buffer size in unit of bytes| Method Detail |
|---|
public void readFileFromStream(String fileName,
long fileSize)
throws IOException
fileName - absolute path of file to be writtenfileSize - file size in bytes
IOException - when file/stream I/O failed
public void readFileFromStream(String fileName,
long offset,
long length)
throws IOException
offset is greater than zero, then the the binary data will
be append to the existing file.
fileName - the output file nameoffset - the offset bytelength - the lenght of byte stream
IOException - when network/file IO failure
public void readFileFromStream(OutputStream out,
long offset,
long length)
throws IOException
out - the output file stream, left open on return.offset - the offset bytelength - the lenght of byte stream
IOException - when network/file IO failure
public void readFileFromStream(OutputStream out,
long offset,
long length,
boolean checksum)
throws IOException
out - the output file stream, left open on return.offset - the offset bytelength - the lenght of byte streamchecksum - True if checksum follows file contents
IOException - when network/file IO failure
public void readBufferFromStream(byte[] buffer,
long fileSize)
throws IOException
buffer - data buffer to store data read from input stream.fileSize - file size in unit of bytes
IOException - when network I/O error occurs
public void readBufferFromStream(byte[] buffer,
long fileSize,
boolean flushChecksum)
throws IOException
buffer - data buffer to store data read from input stream.fileSize - file size in unit of bytesflushChecksum - Flag indicating if checksum needs to be flushed
IOException - when network I/O error occurs
protected byte[] readChecksum()
throws IOException
IOException - if IO error occurs
public void skipFile(long fileSize,
boolean doChecksum)
throws IOException
fileSize - Size of the file to be thrown away.doChecksum - Do we need to flush the checksum too?
IOException - when file I/O fail
public byte[] readAndVerifyFileFromStream(String fileName,
long fileSize)
throws IOException,
VerifyException
calculatedChecksum
updated. See MessageDigest for methods to retrieve
"checksum": toString() and digest().
fileName - absolute path of file to be writtenfileSize - file size in unit of bytes
IOException - when network/file I/O errors
VerifyException - when checksum unmatchedMessageDigest
public byte[] readAndVerifyFileFromStream(String fileName,
long offset,
long length)
throws IOException,
VerifyException
calculatedChecksum updated. If this is a partical file
transfer, then the message digest will be first calculated from byte 0 to
offset before resume transfer-time calculation of message digest. See
MessageDigest for methods to retrieve "checksum":
toString() and digest().
fileName - the name of the fileoffset - the offset value to begin the transferlength - the number of bytes to be transfered
IOException - when network/file IO failure
VerifyException - when checksum failed to verify.
public byte[] readAndVerifyBufferFromStream(byte[] buffer,
long fileSize)
throws IOException,
VerifyException
calculatedChecksum
updated. See MessageDigest for methods to retrieve
"checksum": toString() and digest().
buffer - message digest byte array.fileSize - file size
IOException - when file I/O fail
VerifyException - when comparisons file failMessageDigest
public void writeFileToStream(String fileName,
long fileSize)
throws IOException
fileName - absolute path of file to be readfileSize - file size in unit of bytes
IOException - when network/file I/O error occurs
public void writeFileToStream(String fileName,
long offset,
long length)
throws IOException
fileName - the file name.offset - the offset set to begin the transferlength - the number of bytes to be transfered
IOException - when network/file IO failure.
public byte[] genChecksum(byte[] buffer)
throws IOException
calculatedChecksum updated. See
MessageDigest for methods to retrieve "checksum":
toString() and digest().
buffer - input message digest byte array.
IOException - since the buffer was retrieved from network/file.MessageDigest
public void writeFileToStream(byte[] buffer,
long fileSize)
throws IOException
buffer - in-memory buffer contains the file.fileSize - file size in unit of bytes.
IOException - when general I/O failure
public void writeAndVerifyFileToStream(String fileName,
long fileSize,
byte[] suppliedChecksum)
throws IOException
fileName - absolute path of file to be writtenfileSize - file size in unit of bytessuppliedChecksum - the input checksum value to be sent
IOException - when network/file I/O failureMessageDigest
public void writeAndVerifyFileToStream(String fileName,
long offset,
long length,
byte[] suppliedChecksum)
throws IOException
fileName - the file nameoffset - the offset to begin the transferlength - number of bytes to be transferedsuppliedChecksum - the supplied checksum array.
IOException - when network/file IO failure
public byte[] writeAndVerifyFileToStream(String fileName,
long fileSize)
throws IOException
calculatedChecksum updated. See
MessageDigest for methods to retrieve digest:
toString() and digest().
fileName - absolute path of file to be writtenfileSize - file size in unit of bytes
IOException - when network/file I/O failureMessageDigest
public byte[] writeAndVerifyFileToStream(String fileName,
long offset,
long length)
throws IOException
fileName - the file nameoffset - the offset to begin the transferlength - number of bytes to be transfered
IOException - when network/file IO failure
public byte[] writeAndVerifyBufferToStream(byte[] buffer,
long fileSize)
throws IOException
calculatedChecksum
updated. See MessageDigest for methods to retrieve digest:
toString() and digest().
buffer - file in-memory bufferfileSize - file size in bytes
IOException - when network/file I/O failuresMessageDigest
public MessagePkg readMessage()
throws IOException
writeMessage()
for reply packed format.
IOException - when general I/O failure
public String readLine()
throws IOException
'\n' or '\r' delimited line
IOException - when read failed
public void writeMessage(int errorNum,
String s)
throws IOException
errorNum - the input error value.s - the line to be written
IOException - when write failed
public void writeLine(String s)
throws IOException
s - the line to be written
IOException - when write fails
public void write(String s)
throws IOException
s - the string to be written
IOException - when write fails
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||