Class FileCodestreamWriter
- All Implemented Interfaces:
Markers
Before any packet data is written to the bit stream (even in simulation mode) the complete header should be written to the HeaderEncoder object supplied to the constructor, following the procedure explained in the HeaderEncoder class. Otherwise incorrect estimates are given by getMaxAvailableBytes() for rate allocation.
- See Also:
-
Field Summary
FieldsFields inherited from class jj2000.j2k.codestream.writer.CodestreamWriter
maxBytesFields inherited from interface jj2000.j2k.codestream.Markers
COC, COD, COM, CRG, EOC, EPH, EPH_LENGTH, ERS_SEG_SYMBOLS, ERS_SOP, MAX_COMP_BITDEPTH, MAX_LPPM, MAX_LPPT, PLM, PLT, POC, PPM, PPT, PRECINCT_PARTITION_DEF_SIZE, QCC, QCD, RCOM_GEN_USE, RGN, RSIZ_BASELINE, RSIZ_ER_FLAG, RSIZ_ROI, SCOX_HOR_CB_PART, SCOX_PRECINCT_PARTITION, SCOX_USE_EPH, SCOX_USE_SOP, SCOX_VER_CB_PART, SIZ, SOC, SOD, SOP, SOP_LENGTH, SOT, SQCX_EXP_MASK, SQCX_EXP_SHIFT, SQCX_GB_MSK, SQCX_GB_SHIFT, SQCX_NO_QUANTIZATION, SQCX_SCALAR_DERIVED, SQCX_SCALAR_EXPOUNDED, SRGN_IMPLICIT, SSIZ_DEPTH_BITS, TLM -
Constructor Summary
ConstructorsConstructorDescriptionFileCodestreamWriter(File file, int mb) Opens the file 'file' for writing the bit stream, using the 'he' header encoder.FileCodestreamWriter(OutputStream os, int mb) Uses the output stream 'os' for writing the bit stream, using the 'he' header encoder.FileCodestreamWriter(String fname, int mb) Opens the file named 'fname' for writing the bit stream, using the 'he' header encoder. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Writes the EOC marker and closes the underlying stream.voidWrites the header data in the codestream and actualize ndata with the header length.intReturns the current length of the entire bit stream.final intReturns the number of bytes remaining available in the bit stream.intGives the offset of the end of last packet containing ROI informationintwritePacketBody(byte[] body, int blen, boolean sim, boolean roiInPkt, int roiLen) Writes a packet body to the bit stream and returns the number of bytes used by this body .If in simulation mode then no data is written to the bit stream but the number of bytes is calculated.intwritePacketHead(byte[] head, int hlen, boolean sim, boolean sop, boolean eph) Writes a packet head to the bit stream and returns the number of bytes used by this header.
-
Field Details
-
DEF_BUF_LEN
public static int DEF_BUF_LENThe default buffer length, 1024 bytes
-
-
Constructor Details
-
FileCodestreamWriter
Opens the file 'file' for writing the bit stream, using the 'he' header encoder. The magic number is written to the bit stream. Normally, the header encoder must be empty (i.e. no data has been written to it yet). A BufferedOutputStream is used on top of the file to increase throughput, the length of the buffer is DEF_BUF_LEN.- Parameters:
file- The file where to write the bit streammb- The maximum number of bytes that can be written to the bit stream.- Throws:
IOException- If an error occurs while trying to open the file for writing or while writing the magic number.
-
FileCodestreamWriter
Opens the file named 'fname' for writing the bit stream, using the 'he' header encoder. The magic number is written to the bit stream. Normally, the header encoder must be empty (i.e. no data has been written to it yet). A BufferedOutputStream is used on top of the file to increase throughput, the length of the buffer is DEF_BUF_LEN.- Parameters:
fname- The name of file where to write the bit streammb- The maximum number of bytes that can be written to the bit stream.- Throws:
IOException- If an error occurs while trying to open the file for writing or while writing the magic number.
-
FileCodestreamWriter
Uses the output stream 'os' for writing the bit stream, using the 'he' header encoder. The magic number is written to the bit stream. Normally, the header encoder must be empty (i.e. no data has been written to it yet). No BufferedOutputStream is used on top of the output stream 'os'.- Parameters:
os- The output stream where to write the bit stream.mb- The maximum number of bytes that can be written to the bit stream.- Throws:
IOException- If an error occurs while writing the magic number to the 'os' output stream.
-
-
Method Details
-
getMaxAvailableBytes
public final int getMaxAvailableBytes()Returns the number of bytes remaining available in the bit stream. This is the maximum allowed number of bytes minus the number of bytes that have already been written to the bit stream. If more bytes have been written to the bit stream than the maximum number of allowed bytes, then a negative value is returned.- Specified by:
getMaxAvailableBytesin classCodestreamWriter- Returns:
- The number of bytes remaining available in the bit stream.
-
getLength
public int getLength()Returns the current length of the entire bit stream.- Specified by:
getLengthin classCodestreamWriter- Returns:
- the current length of the bit stream
-
writePacketHead
public int writePacketHead(byte[] head, int hlen, boolean sim, boolean sop, boolean eph) throws IOException Writes a packet head to the bit stream and returns the number of bytes used by this header. It returns the total number of bytes that the packet head takes in the bit stream. If in simulation mode then no data is written to the bit stream but the number of bytes is calculated. This can be used for iterative rate allocation.If the length of the data that is to be written to the bit stream is more than the space left (as returned by getMaxAvailableBytes()) only the data that does not exceed the allowed length is written, the rest is discarded. However the value returned by the method is the total length of the packet, as if all of it was written to the bit stream.
If the bit stream header has not been commited yet and 'sim' is false, then the bit stream header is automatically commited (see commitBitstreamHeader() method) before writting the packet.
- Specified by:
writePacketHeadin classCodestreamWriter- Parameters:
head- The packet head data.hlen- The number of bytes in the packet head.sim- Simulation mode flag. If true nothing is written to the bit stream, but the number of bytes that would be written is returned.sop- Start of packet header marker flag. This flag indicates whether or not SOP markers should be written. If true, SOP markers should be written, if false, they should not.eph- End of Packet Header marker flag. This flag indicates whether or not EPH markers should be written. If true, EPH markers should be written, if false, they should not.- Returns:
- The number of bytes spent by the packet head.
- Throws:
IOException- If an I/O error occurs while writing to the output stream.- See Also:
-
writePacketBody
public int writePacketBody(byte[] body, int blen, boolean sim, boolean roiInPkt, int roiLen) throws IOException Writes a packet body to the bit stream and returns the number of bytes used by this body .If in simulation mode then no data is written to the bit stream but the number of bytes is calculated. This can be used for iterative rate allocation.If the length of the data that is to be written to the bit stream is more than the space left (as returned by getMaxAvailableBytes()) only the data that does not exceed the allowed length is written, the rest is discarded. However the value returned by the method is the total length of the packet body , as if all of it was written to the bit stream.
- Specified by:
writePacketBodyin classCodestreamWriter- Parameters:
body- The packet body data.blen- The number of bytes in the packet body.sim- Simulation mode flag. If true nothing is written to the bit stream, but the number of bytes that would be written is returned.roiInPkt- Whether or not this packet contains ROI informationroiLen- Number of byte to read in packet body to get all the ROI information- Returns:
- The number of bytes spent by the packet body.
- Throws:
IOException- If an I/O error occurs while writing to the output stream.- See Also:
-
close
Writes the EOC marker and closes the underlying stream.- Specified by:
closein classCodestreamWriter- Throws:
IOException- If an error occurs while closing the underlying stream.
-
getOffLastROIPkt
public int getOffLastROIPkt()Gives the offset of the end of last packet containing ROI information- Specified by:
getOffLastROIPktin classCodestreamWriter- Returns:
- End of last ROI packet
-
commitBitstreamHeader
Writes the header data in the codestream and actualize ndata with the header length. The header is either a MainHeaderEncoder or a TileHeaderEncoder.- Specified by:
commitBitstreamHeaderin classCodestreamWriter- Parameters:
he- The current header encoder.- Throws:
IOException- If an I/O error occurs while writing the data.
-