CodeBeamer 5.4.0.1-RC API

com.intland.codebeamer.persistence.util
Class BinaryStreamDtoHelper

java.lang.Object
  extended by com.intland.codebeamer.persistence.util.BinaryStreamDtoHelper

public class BinaryStreamDtoHelper
extends java.lang.Object

Helper object (with lots of static methods) to load/create instances of BinaryStreamDto from various sources. This must be separate class from BinaryStreamDto, because it depends on jars like struts, which are not deployed with the remoting API! See also, the other helper class: @see BinaryStreamDtoHelperStruts.


Field Summary
static int CHUNK_SIZE
           
 
Method Summary
static long copyStream(java.io.InputStream in, java.io.OutputStream out, long maxBytes)
          Must not use Common.copyStream() here, because this class is also used on remote clients, and the Common class references a lot of server side classes !! Copy data from one stream to an other, up to a maximum number of bytes and close all streams afterwards.
static BinaryStreamDto createEmptyStr()
           
static BinaryStreamDto createFromBytes(byte[] bytes2)
          Create it from a set of bytes
static BinaryStreamDto createFromFile(java.io.File file, boolean deleteOnClosed, org.apache.commons.collections.Closure onDeleteFailed)
          Factory method to create from file, which will optionally be deleted after the content is read.
static BinaryStreamDto createFromStream(java.io.InputStream input)
           
static BinaryStreamDto createFromStream(java.io.InputStream in, long length)
           
static BinaryStreamDto loadFromFile(java.io.File file)
          Load a file's full content as byte array into a new BlobStreamDto.
static BinaryStreamDto loadToMemory(BinaryStreamDto dto)
          Loads the internal stream fully into memory.
static void saveToFile(BinaryStreamDto binaryStream, java.io.File outputFile)
          Saves the content of a binary stream to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHUNK_SIZE

public static final int CHUNK_SIZE
See Also:
Constant Field Values
Method Detail

loadToMemory

public static BinaryStreamDto loadToMemory(BinaryStreamDto dto)
                                    throws java.io.IOException
Loads the internal stream fully into memory. BinaryStreamDto's with streams can't be sent through Hessian, because InputStream is not serializable. This methods reads all the bytes from the stream in the BinaryStreamDto and stores that as byte array in the same BinaryStreamDto, because byte arrays are Hessian-compliant. Still after this call the data can only be accessed through getInputStream() method.

Parameters:
dto - is the BinaryStreamDto whose InputStream to load into the bytes array
Throws:
java.io.IOException - If exception during load

loadFromFile

public static BinaryStreamDto loadFromFile(java.io.File file)
                                    throws java.io.IOException
Load a file's full content as byte array into a new BlobStreamDto.

Parameters:
file - the file
Returns:
The new blobStreamDto
Throws:
java.io.IOException

createFromStream

public static BinaryStreamDto createFromStream(java.io.InputStream in,
                                               long length)

createFromBytes

public static BinaryStreamDto createFromBytes(byte[] bytes2)
Create it from a set of bytes

Parameters:
bytes2 -
Returns:
Create from a byte array

createEmptyStr

public static BinaryStreamDto createEmptyStr()

createFromStream

public static BinaryStreamDto createFromStream(java.io.InputStream input)

createFromFile

public static BinaryStreamDto createFromFile(java.io.File file,
                                             boolean deleteOnClosed,
                                             org.apache.commons.collections.Closure onDeleteFailed)
                                      throws java.io.IOException
Factory method to create from file, which will optionally be deleted after the content is read.

Parameters:
file - The file
deleteOnClosed - whether to delete the file after it has been read.
onDeleteFailed - Closure called back when the delete of the file is failed. The closure the AutoClosingInputStream object as parameter.
Throws:
java.io.IOException

saveToFile

public static void saveToFile(BinaryStreamDto binaryStream,
                              java.io.File outputFile)
                       throws java.io.IOException
Saves the content of a binary stream to a file.

Throws:
java.io.IOException

copyStream

public static long copyStream(java.io.InputStream in,
                              java.io.OutputStream out,
                              long maxBytes)
                       throws java.io.IOException
Must not use Common.copyStream() here, because this class is also used on remote clients, and the Common class references a lot of server side classes !! Copy data from one stream to an other, up to a maximum number of bytes and close all streams afterwards.

Parameters:
in - The input stream
out - The output stream
Returns:
The number of bytes got copied
Throws:
java.io.IOException

CodeBeamer 5.4.0.1-RC API

Copyright © 2006-2009 Intland Software. All rights reserved.