public abstract class WriterPoolMember extends Object implements ArchiveFileConstants
WriterPool.
Implements rotating off files, file naming with some guarantee of
uniqueness, and position in file. Subclass to pick up functionality for a
particular Writer type.| Modifier and Type | Field and Description |
|---|---|
protected MiserOutputStream |
countOut
Counting stream for metering
|
protected String |
currentBasename |
protected String |
currentTimestamp
Creation date for the current file.
|
static String |
DEFAULT_PREFIX
Default for file prefix.
|
static String |
DEFAULT_TEMPLATE
Default archival-aggregate filename template.
|
protected File |
f
Reference to file we're currently writing.
|
protected OutputStream |
out
Output stream for file.
|
protected static int |
roundRobinIndex
Directories round-robin index.
|
protected byte[] |
scratchbuffer
Buffer to reuse writing streams.
|
protected static NumberFormat |
serialNoFormatter
NumberFormat instance for formatting serial number.
|
protected WriterPoolSettings |
settings |
static String |
UTF8 |
ABSOLUTE_OFFSET_KEY, CDX, CDX_FILE, CDX_LINE_BUFFER_SIZE, CRLF, DATE_FIELD_KEY, DEFAULT_DIGEST_METHOD, DOT_COMPRESSED_FILE_EXTENSION, DUMP, GZIP_DUMP, HEADER, INVALID_SUFFIX, LENGTH_FIELD_KEY, MIMETYPE_FIELD_KEY, NOHEAD, OCCUPIED_SUFFIX, READER_IDENTIFIER_FIELD_KEY, RECORD_IDENTIFIER_FIELD_KEY, SINGLE_SPACE, TYPE_FIELD_KEY, URL_FIELD_KEY, VERSION_FIELD_KEY| Modifier | Constructor and Description |
|---|---|
protected |
WriterPoolMember(AtomicInteger serialNo,
OutputStream out,
File file,
WriterPoolSettings settings)
Constructor.
|
|
WriterPoolMember(AtomicInteger serialNo,
WriterPoolSettings settings,
String extension)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
checkSize()
Call this method just before/after any significant write.
|
protected File |
checkWriteable(File d) |
void |
close() |
protected long |
copyFrom(InputStream is,
long recordLength,
boolean enforceLength)
Copy bytes from the provided InputStream to the target file/stream being
written.
|
protected String |
createFile()
Create a new file.
|
protected String |
createFile(File file) |
protected void |
flush() |
protected void |
generateNewBasename()
Generate a new basename by interpolating values in the configured
template.
|
protected String |
getBaseFilename()
Get the file name
|
File |
getFile()
Get this file.
|
protected File |
getNextDirectory(List<File> dirs) |
protected OutputStream |
getOutputStream() |
long |
getPosition()
Position in raw output (typically, physical file).
|
boolean |
isCompressed() |
boolean |
isOversize()
Check if underlying file has already reached its target size.
|
protected void |
postWriteRecordTasks()
Post file write tasks.
|
protected void |
preWriteRecordTasks()
Post write tasks.
|
protected void |
write(byte[] b) |
protected void |
write(byte[] b,
int off,
int len) |
protected void |
write(int b) |
public static final String UTF8
public static final String DEFAULT_TEMPLATE
public static final String DEFAULT_PREFIX
protected File f
protected OutputStream out
protected MiserOutputStream countOut
protected WriterPoolSettings settings
protected String currentTimestamp
createFile().protected String currentBasename
protected static int roundRobinIndex
protected static NumberFormat serialNoFormatter
protected final byte[] scratchbuffer
protected WriterPoolMember(AtomicInteger serialNo, OutputStream out, File file, WriterPoolSettings settings) throws IOException
serialNo - used to create unique filename sequencesout - Where to write.file - File the out is connected to.cmprs - Compress the content written.a14DigitDate - If null, we'll write current time.IOExceptionpublic WriterPoolMember(AtomicInteger serialNo, WriterPoolSettings settings, String extension)
serialNo - used to create unique filename sequencesdirs - Where to drop files.prefix - File prefix to use.cmprs - Compress the records written.maxSize - Maximum size for ARC files written.template - filenaming template to useextension - Extension to give file.public void checkSize()
throws IOException
Creates and opens a file if none already open. One use of this method
then is after construction, call this method to add the metadata, then
call getPosition() to find offset of first record.
TODO: perhaps this should be called checkForNewOpen? because it also
handles initial open, even when not rolling oversize
IOExceptionpublic boolean isOversize()
protected String createFile() throws IOException
checkSize().IOExceptionprotected String createFile(File file) throws IOException
IOExceptionprotected File getNextDirectory(List<File> dirs) throws IOException
dirs - List of File objects that point at directories.IOExceptionprotected void generateNewBasename()
protected String getBaseFilename()
public File getFile()
WriterPool wants
to invalidate a file.protected void preWriteRecordTasks()
throws IOException
IOExceptionprotected void postWriteRecordTasks()
throws IOException
IOExceptionpublic long getPosition()
IOExceptionpublic boolean isCompressed()
protected void write(byte[] b)
throws IOException
IOExceptionprotected void flush()
throws IOException
IOExceptionprotected void write(byte[] b,
int off,
int len)
throws IOException
IOExceptionprotected void write(int b)
throws IOException
IOExceptionprotected long copyFrom(InputStream is, long recordLength, boolean enforceLength) throws IOException
is - InputStream to copy bytes fromrecordLength - expected number of bytes to copyenforceLength - whether to throw an exception if too many/too few bytes are
available from streamenforceLength)IOExceptionpublic void close()
throws IOException
IOExceptionprotected OutputStream getOutputStream()
Copyright © 2015 The International Internet Preservation Consortium. All Rights Reserved.