public abstract class WriterPoolMember extends java.lang.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 java.lang.String |
currentBasename |
protected java.lang.String |
currentTimestamp
Creation date for the current file.
|
static java.lang.String |
DEFAULT_PREFIX
Default for file prefix.
|
static java.lang.String |
DEFAULT_TEMPLATE
Default archival-aggregate filename template.
|
protected java.io.File |
f
Reference to file we're currently writing.
|
protected java.io.OutputStream |
out
Output stream for file.
|
protected static int |
roundRobinIndex
Directories round-robin index.
|
protected byte[] |
scratchbuffer
Buffer to reuse writing streams.
|
protected static java.text.NumberFormat |
serialNoFormatter
NumberFormat instance for formatting serial number.
|
protected WriterPoolSettings |
settings |
static java.lang.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, ORIGIN_FIELD_KEY, 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(java.util.concurrent.atomic.AtomicInteger serialNo,
java.io.OutputStream out,
java.io.File file,
WriterPoolSettings settings)
Constructor.
|
|
WriterPoolMember(java.util.concurrent.atomic.AtomicInteger serialNo,
WriterPoolSettings settings,
java.lang.String extension)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
checkSize()
Call this method just before/after any significant write.
|
protected java.io.File |
checkWriteable(java.io.File d) |
void |
close() |
protected long |
copyFrom(java.io.InputStream is,
long recordLength,
boolean enforceLength)
Copy bytes from the provided InputStream to the target file/stream being
written.
|
protected java.lang.String |
createFile()
Create a new file.
|
protected java.lang.String |
createFile(java.io.File file) |
protected void |
flush() |
protected void |
generateNewBasename()
Generate a new basename by interpolating values in the configured
template.
|
protected java.lang.String |
getBaseFilename()
Get the file name
|
java.io.File |
getFile()
Get this file.
|
protected java.io.File |
getNextDirectory(java.util.List<java.io.File> dirs) |
protected java.io.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 java.lang.String UTF8
public static final java.lang.String DEFAULT_TEMPLATE
public static final java.lang.String DEFAULT_PREFIX
protected java.io.File f
protected java.io.OutputStream out
protected MiserOutputStream countOut
protected WriterPoolSettings settings
protected java.lang.String currentTimestamp
createFile().protected java.lang.String currentBasename
protected static int roundRobinIndex
protected static java.text.NumberFormat serialNoFormatter
protected final byte[] scratchbuffer
protected WriterPoolMember(java.util.concurrent.atomic.AtomicInteger serialNo,
java.io.OutputStream out,
java.io.File file,
WriterPoolSettings settings)
throws java.io.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.java.io.IOExceptionpublic WriterPoolMember(java.util.concurrent.atomic.AtomicInteger serialNo,
WriterPoolSettings settings,
java.lang.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 java.io.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
java.io.IOExceptionpublic boolean isOversize()
protected java.lang.String createFile()
throws java.io.IOException
checkSize().java.io.IOExceptionprotected java.lang.String createFile(java.io.File file)
throws java.io.IOException
java.io.IOExceptionprotected java.io.File getNextDirectory(java.util.List<java.io.File> dirs)
throws java.io.IOException
dirs - List of File objects that point at directories.java.io.IOExceptionprotected java.io.File checkWriteable(java.io.File d)
protected void generateNewBasename()
protected java.lang.String getBaseFilename()
public java.io.File getFile()
WriterPool wants
to invalidate a file.protected void preWriteRecordTasks()
throws java.io.IOException
java.io.IOExceptionprotected void postWriteRecordTasks()
throws java.io.IOException
java.io.IOExceptionpublic long getPosition()
java.io.IOExceptionpublic boolean isCompressed()
protected void write(byte[] b)
throws java.io.IOException
java.io.IOExceptionprotected void flush()
throws java.io.IOException
java.io.IOExceptionprotected void write(byte[] b,
int off,
int len)
throws java.io.IOException
java.io.IOExceptionprotected void write(int b)
throws java.io.IOException
java.io.IOExceptionprotected long copyFrom(java.io.InputStream is,
long recordLength,
boolean enforceLength)
throws java.io.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)java.io.IOExceptionpublic void close()
throws java.io.IOException
java.io.IOExceptionprotected java.io.OutputStream getOutputStream()
Copyright © 2019 The International Internet Preservation Consortium. All Rights Reserved.