binaryFileStorage
Class BinaryOutputStream

java.lang.Object
  extended by binaryFileStorage.BinaryOutputStream

public class BinaryOutputStream
extends java.lang.Object

Handles writing of an actual binary data file.

Is used during data analysis and also to rewrite files if they are changed during offline analysis using the PAMGUARD viewer.

Author:
Doug Gillespie
See Also:
BinaryStore

Field Summary
private  BinaryDataSource binaryDataSource
           
private  BinaryStore binaryStore
           
private  java.io.DataOutputStream dataOutputStream
           
private  BinaryFooter footer
           
private  BinaryHeader header
           
private  java.lang.String indexFileName
           
private  java.lang.String mainFileName
           
private  byte[] moduleFooterData
           
private  byte[] moduleHeaderData
           
private  PamDataBlock parentDataBlock
           
private  int storedObjects
           
 
Constructor Summary
BinaryOutputStream(BinaryStore binaryStore, PamDataBlock parentDataBlock)
           
 
Method Summary
 boolean closeFile()
           
private  boolean createFileNames(long dataTime)
          Create names for the main storage file and also for the corresponding index file.
 boolean createIndexFile()
           
 boolean createIndexFile(java.io.File indexFile)
           
private  java.lang.String fillSpaces(java.lang.String str)
          Fill blank spaces in a string.
protected  void finalize()
           
private  long getSamplesFromMilliseconds(long timeMillis)
           
 boolean openFile(java.io.File outputFile)
          Open an output file.
 boolean openFile(long dataTime)
          Open an output file.
protected  void reOpen(long dataTime, long analTime, int endReason)
           
 boolean storeData(BinaryObjectData binaryObjectData)
          Write data to a file.
 boolean storeData(int objectId, long timeMillis, byte[] data)
          Write data to a file
 boolean storeData(int objectId, long timeMillis, byte[] data, int objectLength)
          Writes data to a file.
 boolean writeFooter(long dataTime, long analTime, int endReason)
           
 boolean writeHeader(long dataTime, long analTime)
           
 boolean writeModuleFooter()
           
 boolean writeModuleFooter(byte[] footerData)
           
 boolean writeModuleFooter(java.io.DataOutputStream outputStream, byte[] footerData)
           
 boolean writeModuleHeader()
           
 boolean writeModuleHeader(byte[] headerData)
           
 boolean writeModuleHeader(java.io.DataOutputStream outputStream, byte[] headerData)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parentDataBlock

private PamDataBlock parentDataBlock

binaryDataSource

private BinaryDataSource binaryDataSource

binaryStore

private BinaryStore binaryStore

header

private BinaryHeader header

footer

private BinaryFooter footer

moduleHeaderData

private byte[] moduleHeaderData

moduleFooterData

private byte[] moduleFooterData

dataOutputStream

private java.io.DataOutputStream dataOutputStream

storedObjects

private int storedObjects

mainFileName

private java.lang.String mainFileName

indexFileName

private java.lang.String indexFileName
Constructor Detail

BinaryOutputStream

public BinaryOutputStream(BinaryStore binaryStore,
                          PamDataBlock parentDataBlock)
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

reOpen

protected void reOpen(long dataTime,
                      long analTime,
                      int endReason)

openFile

public boolean openFile(long dataTime)
Open an output file.

this call is used in real time ops to create a new file name based on the time and information from the datablock name.

Parameters:
dataTime - time in Java milliseconds
Returns:
true if successful, false otherwise.

openFile

public boolean openFile(java.io.File outputFile)
Open an output file.

This version is used when rewriting files when data have been changed offline. Generally the file will be a .tmp file

Parameters:
outputFile - output file
Returns:
true if successful

createFileNames

private boolean createFileNames(long dataTime)
Create names for the main storage file and also for the corresponding index file.

Parameters:
dataTime - time in milliseconds.
Returns:
true if folder is OK and file names have been created.

fillSpaces

private java.lang.String fillSpaces(java.lang.String str)
Fill blank spaces in a string.

Parameters:
str -
Returns:
string with spaces replaced with the underscore character

closeFile

public boolean closeFile()

getSamplesFromMilliseconds

private long getSamplesFromMilliseconds(long timeMillis)

writeHeader

public boolean writeHeader(long dataTime,
                           long analTime)

writeModuleHeader

public boolean writeModuleHeader()

writeModuleHeader

public boolean writeModuleHeader(byte[] headerData)

writeModuleHeader

public boolean writeModuleHeader(java.io.DataOutputStream outputStream,
                                 byte[] headerData)

writeModuleFooter

public boolean writeModuleFooter()

writeModuleFooter

public boolean writeModuleFooter(byte[] footerData)

writeModuleFooter

public boolean writeModuleFooter(java.io.DataOutputStream outputStream,
                                 byte[] footerData)

writeFooter

public boolean writeFooter(long dataTime,
                           long analTime,
                           int endReason)

storeData

public boolean storeData(int objectId,
                         long timeMillis,
                         byte[] data)
Write data to a file

Parameters:
objectId - unique object identifier.
timeMillis - time of object in java milliseconds
data - byte array of binary data to store.
Returns:
true if written successfully.

storeData

public boolean storeData(BinaryObjectData binaryObjectData)
Write data to a file.

Parameters:
binaryObjectData - data to store.
Returns:
true if written successfully

storeData

public boolean storeData(int objectId,
                         long timeMillis,
                         byte[] data,
                         int objectLength)
Writes data to a file. Note that the length of data may be greater than the actual length of useful data which is held in onjectLength

Parameters:
objectId - unique object identifier.
timeMillis - time of object in java milliseconds
data - byte array of binary data to store.
objectLength - length of useful data in data (often = data.length)
Returns:
true if written successfully.

createIndexFile

public boolean createIndexFile()

createIndexFile

public boolean createIndexFile(java.io.File indexFile)