|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.onionnetworks.fec.io.FECFile
public class FECFile
This class provides the necessary file IO routines to go along with the raw
FEC codes. It is completely thread safe for multiple readers and writers,
and will automatically encode and decode the packets ass necessary. If
the FECFile is originally opened in "rw" mode it will revert to "r" mode
once it has recieved enough data and decoded the entire file.
File Encoding Example:
File f = new File(args[0]);
int k = 32; // source packet per block
int n = 256; // number of packets to expand each block to.
int packetSize = 1024; // number of bytes in each packet.
FECParameters params = new FECParameters(k,n,packetSize,f.length());
FECFile fecF = new FECFile(f,"r",params);
// Read the packet with blockNum=0,stripeNum=32 into the Buffer
// The read() interface is much faster if you encode multiple packets
// per block and encourages you to do so. We are not going to for
// simplicity.
Buffer b = new Buffer(packetSize);
fecF.read(new Buffer[] {b}, 0, new int[] {32});
Please see tests/FECFileTest for a further example.
Nested Class Summary | |
---|---|
class |
FECFile.Decoder
|
Constructor Summary | |
---|---|
FECFile(java.io.File f,
java.lang.String mode,
FECParameters params)
Open the file according to mode
| |
FECFile(java.io.File f,
java.lang.String mode,
FECParameters params,
com.onionnetworks.util.FileIntegrity integrity)
Open the file according to mode
|
Method Summary | |
---|---|
void |
acquireAllWriteLocks()
Acquires all write block locks. |
void |
addFECIOListener(FECIOListener fil)
Adds a new FECIOListener. |
void |
close()
Close the underlying file descriptor and free up the resources associated with this FECFile. |
boolean |
containsPacket(int blockNum,
int stripeNum)
|
int |
getDecodedBlockCount()
|
FECParameters |
getFECParameters()
|
int |
getWrittenCount()
|
boolean |
isBlockDecoded(int blockNum)
|
boolean |
isDecoded()
|
void |
read(com.onionnetworks.util.Buffer[] pkts,
int blockNum,
int[] stripeNums)
This method reads a number of packets (encoding them if necessary) into the provided buffers. |
void |
releaseAllWriteLocks()
Releases all write block locks. |
void |
removeFECIOListener(FECIOListener fil)
|
void |
renameTo(java.io.File destFile)
When the File is opened in r/w mode you must specify a destination. |
void |
setDecodeExceptionHandler(com.onionnetworks.util.ExceptionHandler eh)
Sets the ExceptionHandler for dealing with problems that occur during decoding. |
void |
waitForFileDecoded()
This method blocks and returns once the file has been decoded. |
int |
write(com.onionnetworks.util.Buffer pkt,
int blockNum,
int stripeNum)
Writes a packet to disk. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FECFile(java.io.File f, java.lang.String mode, FECParameters params) throws java.io.IOException
mode
f
- The File to which the data will be read/writtenmode
- Either "r" or "rw"params
- The FECParameters that specify how the data will be
encoded and decoded.
java.io.IOException
public FECFile(java.io.File f, java.lang.String mode, FECParameters params, com.onionnetworks.util.FileIntegrity integrity) throws java.io.IOException
mode
f
- The File to which the data will be read/writtenmode
- Either "r" or "rw"params
- The FECParameters that specify how the data will be
encoded and decoded.integrity
- Used for checking the file integrity.
java.io.IOException
Method Detail |
---|
public void setDecodeExceptionHandler(com.onionnetworks.util.ExceptionHandler eh)
ExceptionHandler
- This object that will handle the exception.public void renameTo(java.io.File destFile) throws java.io.IOException
java.io.IOException
public void read(com.onionnetworks.util.Buffer[] pkts, int blockNum, int[] stripeNums) throws java.io.IOException, PacketNotFoundException
pkts
- The array of Buffers into which the data will be stored
each Buffer must be params.getPacketSize()
in length.blockNum
- The block num of the packets to encode.stripeNums
- The stripe nums of the packets to encode.
java.io.IOException
- If there is an IOException in the underlying file
IO.
PacketNotFoundException
- If the desired packet can not be found
in the PacketPlacement.public int write(com.onionnetworks.util.Buffer pkt, int blockNum, int stripeNum) throws java.io.IOException, FileAlreadyDecodedException
pkt
- The Buffer from which the data will be written.blockNum
- The blockNum of the packet to be written.stripeNum
- The stripeNum of the packet to be written.
java.io.IOException
- When there is a disk IOException.
DuplicatePacketException
- When there is an attempt to write a
packet a second time.
BlockAlreadyDecodedException
- When the block is already decoded.
FileAlreadyDecodedException
- When you are trying to write a
packet when the file has been decoded and switched to read-onlypublic void acquireAllWriteLocks() throws java.lang.InterruptedException
java.lang.InterruptedException
public void releaseAllWriteLocks() throws java.lang.InterruptedException
java.lang.InterruptedException
public void close() throws java.io.IOException
java.io.IOException
public void addFECIOListener(FECIOListener fil)
public void removeFECIOListener(FECIOListener fil)
public int getDecodedBlockCount()
public boolean isBlockDecoded(int blockNum)
public boolean containsPacket(int blockNum, int stripeNum)
public int getWrittenCount()
public FECParameters getFECParameters()
public boolean isDecoded()
public void waitForFileDecoded() throws java.lang.InterruptedException
java.lang.InterruptedException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |