Top Description Fields Constructors Methods
org.apache.tools.tar

public Class TarBuffer

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, .OutputStream, java.util.Arrays

The TarBuffer class implements the tar archive concept of a buffered input stream. This concept goes back to the days of blocked tape drives and special io devices. In the Java universe, the only real function that this class performs is to ensure that files have the correct "block" size, or other tars will complain.

You should never have a need to access this class directly. TarBuffers are created by Tar IO Streams.

Field Summary

Modifier and TypeField and Description
private final byte[]
private final int
private int
private int
private boolean
public static final int
DEFAULT_BLKSIZE

Default block size

public static final int
DEFAULT_RCDSIZE

Default record size

private InputStream
private OutputStream
private final int
private final int

Constructor Summary

AccessConstructor and Description
public
TarBuffer(InputStream
the input stream to use
inStream
)

Constructor for a TarBuffer on an input stream.

public
TarBuffer(InputStream
the input stream to use
inStream
,
int
the block size to use
blockSize
)

Constructor for a TarBuffer on an input stream.

public
TarBuffer(InputStream
the input stream to use
inStream
,
int
the block size to use
blockSize
,
int
the record size to use
recordSize
)

Constructor for a TarBuffer on an input stream.

public
TarBuffer(OutputStream
the output stream to use
outStream
)

Constructor for a TarBuffer on an output stream.

public
TarBuffer(OutputStream
the output stream to use
outStream
,
int
the block size to use
blockSize
)

Constructor for a TarBuffer on an output stream.

public
TarBuffer(OutputStream
the output stream to use
outStream
,
int
the block size to use
blockSize
,
int
the record size to use
recordSize
)

Constructor for a TarBuffer on an output stream.

private
TarBuffer(InputStream inStream, OutputStream outStream, int blockSize, int recordSize)

Private constructor to perform common setup.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Close the TarBuffer.

pack-priv void
flushBlock()

Flush the current data block if it has any data in it.

public int

Returns:

the block size
getBlockSize
()

Get the TAR Buffer's block size.

public int

Returns:

The current zero based block number.
getCurrentBlockNum
()

Get the current block number, zero based.

public int

Returns:

The current zero based record number.
getCurrentRecordNum
()

Get the current record number, within the current block, zero based.

public int

Returns:

the record size
getRecordSize
()

Get the TAR Buffer's record size.

public boolean

Returns:

true if the record data is an End of Archive
isEOFRecord
(byte[]
The record data to check.
record
)

Determine if an archive record indicate End of Archive.

private boolean

Returns:

false if End-Of-File, else true
readBlock
()

public byte[]

Returns:

The record data.
readRecord
()

Read a record from the input stream and return the data.

public void
setDebug(boolean
If true, print debugging output.
debug
)

Set the debugging flag for the buffer.

public void
skipRecord()

Skip over a record on the input stream.

private void
writeBlock()

Write a TarBuffer block to the archive.

public void
writeRecord(byte[]
The record data to write to the archive.
record
)

Write an archive record to the archive.

public void
writeRecord(byte[]
The buffer containing the record data to write.
buf
,
int
The offset of the record data within buf.
offset
)

Write an archive record to the archive, where the record may be inside of a larger array buffer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blockBufferback to summary
private final byte[] blockBuffer
blockSizeback to summary
private final int blockSize
currBlkIdxback to summary
private int currBlkIdx
currRecIdxback to summary
private int currRecIdx
debugback to summary
private boolean debug
DEFAULT_BLKSIZEback to summary
public static final int DEFAULT_BLKSIZE

Default block size

DEFAULT_RCDSIZEback to summary
public static final int DEFAULT_RCDSIZE

Default record size

inStreamback to summary
private InputStream inStream
outStreamback to summary
private OutputStream outStream
recordSizeback to summary
private final int recordSize
recsPerBlockback to summary
private final int recsPerBlock

Constructor Detail

TarBufferback to summary
public TarBuffer(InputStream inStream)

Constructor for a TarBuffer on an input stream.

Parameters
inStream:InputStream

the input stream to use

TarBufferback to summary
public TarBuffer(InputStream inStream, int blockSize)

Constructor for a TarBuffer on an input stream.

Parameters
inStream:InputStream

the input stream to use

blockSize:int

the block size to use

TarBufferback to summary
public TarBuffer(InputStream inStream, int blockSize, int recordSize)

Constructor for a TarBuffer on an input stream.

Parameters
inStream:InputStream

the input stream to use

blockSize:int

the block size to use

recordSize:int

the record size to use

TarBufferback to summary
public TarBuffer(OutputStream outStream)

Constructor for a TarBuffer on an output stream.

Parameters
outStream:OutputStream

the output stream to use

TarBufferback to summary
public TarBuffer(OutputStream outStream, int blockSize)

Constructor for a TarBuffer on an output stream.

Parameters
outStream:OutputStream

the output stream to use

blockSize:int

the block size to use

TarBufferback to summary
public TarBuffer(OutputStream outStream, int blockSize, int recordSize)

Constructor for a TarBuffer on an output stream.

Parameters
outStream:OutputStream

the output stream to use

blockSize:int

the block size to use

recordSize:int

the record size to use

TarBufferback to summary
private TarBuffer(InputStream inStream, OutputStream outStream, int blockSize, int recordSize)

Private constructor to perform common setup.

Method Detail

closeback to summary
public void close() throws IOException

Close the TarBuffer. If this is an output buffer, also flush the current block before closing.

Exceptions
IOException:
on error
flushBlockback to summary
pack-priv void flushBlock() throws IOException

Flush the current data block if it has any data in it.

getBlockSizeback to summary
public int getBlockSize()

Get the TAR Buffer's block size. Blocks consist of multiple records.

Returns:int

the block size

getCurrentBlockNumback to summary
public int getCurrentBlockNum()

Get the current block number, zero based.

Returns:int

The current zero based block number.

getCurrentRecordNumback to summary
public int getCurrentRecordNum()

Get the current record number, within the current block, zero based. Thus, current offset = (currentBlockNum * recsPerBlk) + currentRecNum.

Returns:int

The current zero based record number.

getRecordSizeback to summary
public int getRecordSize()

Get the TAR Buffer's record size.

Returns:int

the record size

isEOFRecordback to summary
public boolean isEOFRecord(byte[] record)

Determine if an archive record indicate End of Archive. End of archive is indicated by a record that consists entirely of null bytes.

Parameters
record:byte[]

The record data to check.

Returns:boolean

true if the record data is an End of Archive

readBlockback to summary
private boolean readBlock() throws IOException
Returns:boolean

false if End-Of-File, else true

readRecordback to summary
public byte[] readRecord() throws IOException

Read a record from the input stream and return the data.

Returns:byte[]

The record data.

Exceptions
IOException:
on error
setDebugback to summary
public void setDebug(boolean debug)

Set the debugging flag for the buffer.

Parameters
debug:boolean

If true, print debugging output.

skipRecordback to summary
public void skipRecord() throws IOException

Skip over a record on the input stream.

Exceptions
IOException:
on error
writeBlockback to summary
private void writeBlock() throws IOException

Write a TarBuffer block to the archive.

writeRecordback to summary
public void writeRecord(byte[] record) throws IOException

Write an archive record to the archive.

Parameters
record:byte[]

The record data to write to the archive.

Exceptions
IOException:
on error
writeRecordback to summary
public void writeRecord(byte[] buf, int offset) throws IOException

Write an archive record to the archive, where the record may be inside of a larger array buffer. The buffer must be "offset plus record size" long.

Parameters
buf:byte[]

The buffer containing the record data to write.

offset:int

The offset of the record data within buf.

Exceptions
IOException:
on error