|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.at4j.tar.builder.V7TarEntryStrategy
public class V7TarEntryStrategy
This TarEntryStrategy
creates Tar entries conforming to the old Unix
v7 format. The entries created by this strategy contain the following data:
Property | Comment |
---|---|
Absolute location of the entry | Limited to 99 characters, excluding the initial slash. |
UnixEntityMode |
A Unix file permission mode such as 0644 or 0755 . |
Owner UID | The user id of the owner of the file system entity that the Tar entry was
created from. This may be a value between 0 and 2097151
(inclusive). |
Owner GID | The group id of the group that owns the file system entity that the tar
entry was created from. This may be a value between 0 and 2097151 (inclusive). |
File size | For files, this is a value between 0 and 8589934591 bytes
(~ 8.6 Gb), inclusive. |
Link name | For symbolic links, this is the link target. Limited to 99 characters. |
Constructor Summary | |
---|---|
V7TarEntryStrategy()
Create a new strategy object that will use the platform's default character encoding to encode text values in the Tar entries. |
|
V7TarEntryStrategy(Charset cs)
Create a new strategy object that will use the supplied charset for encoding test values in the Tar entries. |
Method Summary | |
---|---|
protected byte[] |
addChecksumToHeader(byte[] header)
Add the checksum field to the Tar entry header. |
protected String |
getFileName(AbsoluteLocation location,
boolean directory)
Get the file name for the supplied location, discarding the path up to the file name. |
protected byte[] |
getHeader(Object entity,
String fileName,
TarEntrySettings effectiveSettings,
long fileSize,
EntityType entityType,
Date lastModified)
Create a Tar header for the new entry. |
protected Charset |
getTextEncodingCharset()
Get the charset that is used to encode text values in Tar entries. |
protected void |
goToNextBlockBoundary(DataSink out,
long sizeOfDataWritten)
Set the current position of the DataSink to be on the next tar
block boundary after a writing operation. |
protected void |
setFileNameInHeader(byte[] header,
String fileName)
Set the file name field in the Tar entry header. |
void |
writeDirectory(DataSink out,
DirectoryAdapter<?> da,
AbsoluteLocation location,
TarEntrySettings effectiveSettings,
Date lastModified)
Write a directory entry to the Tar file. |
void |
writeFile(DataSink out,
ReadableFile f,
AbsoluteLocation location,
TarEntrySettings effectiveSettings,
Date lastModified)
Write a file entry to the Tar file. |
void |
writeFileFromStream(RandomAccess out,
InputStream is,
AbsoluteLocation location,
TarEntrySettings effectiveSettings,
Date lastModified)
Write a file entry containing all data that can be read from the stream to the Tar file. |
protected long |
writeFileToArchive(DataSink out,
ReadableFile f,
TarEntrySettings effectiveSettings)
Write the contents of the supplied file to the archive. |
protected byte[] |
zeroPadLeft(String s,
int size)
Add zeroes to the left of the supplied string so that it will have the requested size, and then convert the string to bytes using the platform's default charset. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public V7TarEntryStrategy()
V7TarEntryStrategy(Charset)
public V7TarEntryStrategy(Charset cs)
cs
- The charset.V7TarEntryStrategy()
Method Detail |
---|
protected final Charset getTextEncodingCharset()
protected byte[] zeroPadLeft(String s, int size)
s
- The string to zero pad.size
- The requested size of the returned array.
protected void goToNextBlockBoundary(DataSink out, long sizeOfDataWritten) throws WrappedIOException
DataSink
to be on the next tar
block boundary after a writing operation. Tar blocks are 512 bytes big.
out
- The RandomAccess
.sizeOfDataWritten
- The size of the data that was written. It is
assumed that the write started on a block boundary.
WrappedIOException
- On I/O errors.protected String getFileName(AbsoluteLocation location, boolean directory)
location
- The absolute location.directory
- Should the file name be for a directory?
protected void setFileNameInHeader(byte[] header, String fileName) throws ArchiveEntryAddException
ArchiveEntryAddException
if the file name is longer
than 99 bytes. Subclasses may override this method to implement a
different behavior.
header
- The header to add the file name to.fileName
- The file name to add.
ArchiveEntryAddException
- If the file name is longer than 99
bytes.protected byte[] getHeader(Object entity, String fileName, TarEntrySettings effectiveSettings, long fileSize, EntityType entityType, Date lastModified) throws ArchiveEntryAddException
This implementation creates a Unix v7 header (of course). Subclasses may override this method to create other kinds of headers.
This method uses the setFileNameInHeader(byte[], String)
method
to set the file name.
entity
- The entity that the Tar entry should represent. This may be
a file, a directory or an InputStream
.fileName
- The name of the entity.effectiveSettings
- Effective settings for the entry.fileSize
- If the entry is a file entry, this value contains the
file size in bytes.entityType
- The type of the entity being added.lastModified
- When the entity was last modified.
addChecksumToHeader(byte[])
method may be used to calculate the
header's checksum when all data has been added to it.
ArchiveEntryAddException
- If the entry cannot be created, for some
reason.protected long writeFileToArchive(DataSink out, ReadableFile f, TarEntrySettings effectiveSettings) throws WrappedIOException
out
- The RandomAccess
to write to. When this method is
called, it should be positioned at the start of the first block of the
file data (just after the file entry header). When this method returns,
the RandomAccess
is positioned just after the written data. (I.e:
probably not at the next Tar block boundary). If this method throws an
exception, the position of the RandomAccess
is unspecified.
WrappedIOException
- On I/O errors.protected byte[] addChecksumToHeader(byte[] header)
This method should be called after all data has been added to the tar entry header.
header
- The Tar entry header.
header
.)public void writeFile(DataSink out, ReadableFile f, AbsoluteLocation location, TarEntrySettings effectiveSettings, Date lastModified)
TarEntryStrategy
writeFile
in interface TarEntryStrategy
out
- The DataSink
to write to. This may be a
RandomAccess
object. When this method is called, the DataSink
is positioned at the start of the entry to write. If this
method returns successfully, the DataSink
should be positioned at
the next block boundary after the written entry (the Tar file is divided
into 512-byte blocks).f
- The file to add to the archive. If this file is in a locking
FileSystem
, it is locked for reading by the caller before this
method is called.location
- The absolute location of the entry in the Tar archive.effectiveSettings
- The effective settings for the entry.lastModified
- The time when the file entity was last modified.public void writeFileFromStream(RandomAccess out, InputStream is, AbsoluteLocation location, TarEntrySettings effectiveSettings, Date lastModified)
TarEntryStrategy
writeFileFromStream
in interface TarEntryStrategy
out
- The RandomAccess
to write to. When this method is
called, the RandomAccess
is positioned at the start of the entry
to write. If this method returns successfully, the RandomAccess
should be positioned at the next block boundary after the written entry
(the Tar file is divided into 512-byte blocks).is
- The stream containing the file's data.location
- The absolute location of the entry in the Tar archive.effectiveSettings
- The effective settings for the entry.lastModified
- The time when the file entity was last modified.public void writeDirectory(DataSink out, DirectoryAdapter<?> da, AbsoluteLocation location, TarEntrySettings effectiveSettings, Date lastModified)
TarEntryStrategy
writeDirectory
in interface TarEntryStrategy
out
- The DataSink
to write to. This may be a
RandomAccess
object. When this method is called, the DataSink
is positioned at the start of the entry to write. If this
method returns successfully, the DataSink
should be positioned at
the next block boundary after the written entry (the Tar file is divided
into 512-byte blocks).da
- The directory to add to the Tar file.location
- The absolute location of the entry in the Tar archive.effectiveSettings
- The effective settings for the entry.lastModified
- The time when the directory entity was last modified.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |