2.17.2: 2011-06-17

net.sf.basedb.core
Class File.UploadStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by java.io.BufferedOutputStream
              extended by net.sf.basedb.core.File.UploadStream
All Implemented Interfaces:
Closeable, Flushable
Enclosing class:
File

private class File.UploadStream
extends BufferedOutputStream

This class is used for uploading a file. It keeps track of the number of bytes uploaded and sets the size accordingly.

See Also:
File.getUploadStream(boolean)

Field Summary
private  boolean checkMd5
          If the md5 should be checked or not.
private  boolean closed
          If this file closed or not.
private  boolean compress
          If the file should be compressed or not.
private  File file
          The file to write to.
private  MessageDigest md5
          The md5 sum calculater.
private  long totalBytes
          Number of bytes written to the stream.
 
Fields inherited from class java.io.BufferedOutputStream
buf, count
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
private File.UploadStream(File file, boolean calculateMd5, boolean checkMd5, boolean compress)
          Create a new UploadStream and connect it to the given file.
 
Method Summary
 void close()
          Close the stream and register the size and location with the file item.
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
          Writes the specified byte to this buffered output stream.
 
Methods inherited from class java.io.BufferedOutputStream
flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

closed

private boolean closed
If this file closed or not.


totalBytes

private long totalBytes
Number of bytes written to the stream.


md5

private MessageDigest md5
The md5 sum calculater.


file

private File file
The file to write to.


compress

private boolean compress
If the file should be compressed or not.


checkMd5

private boolean checkMd5
If the md5 should be checked or not.

Constructor Detail

File.UploadStream

private File.UploadStream(File file,
                          boolean calculateMd5,
                          boolean checkMd5,
                          boolean compress)
                   throws IOException
Create a new UploadStream and connect it to the given file.

Parameters:
file - The physical file path to which the stream will write
calculateMd5 - TRUE if an md5 sum should be calculated from this uploadstream
checkMd5 - If the md5 sum of the file should be checked agains the previously stored md5 sum, useful for making sure secondary storage is working properly
Throws:
IOException - If there is an error during the upload
Method Detail

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Overrides:
write in class BufferedOutputStream
Throws:
IOException

write

public void write(byte[] b)
           throws IOException
Overrides:
write in class FilterOutputStream
Throws:
IOException

write

public void write(int b)
           throws IOException
Writes the specified byte to this buffered output stream.

Overrides:
write in class BufferedOutputStream
Parameters:
b - the byte to be written.
Throws:
IOException - if an I/O error occurs.
See Also:
BufferedOutputStream.write(int)

close

public void close()
           throws IOException
Close the stream and register the size and location with the file item.

Specified by:
close in interface Closeable
Overrides:
close in class FilterOutputStream
Throws:
IOException - if an I/O error occurs.

2.17.2: 2011-06-17