java.lang.Object
java.io.OutputStream
eu.steffo.cleaver.logic.split.SplitFileOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
public class SplitFileOutputStream extends OutputStream
A custom
OutputStream
that writes the bytes received in input in multiple files with a progressively increasing number (.c1, .c2, .c3, and so on).
Bytes are written to a file until its length reaches maximumByteCount
, then the program switches to the following file (.c2 if .c1 is full, .c3 if .c2 is full, and so on).-
Field Summary
Fields Modifier and Type Field Description private long
currentByteCount
private int
currentFileCount
protected FileOutputStream
currentFileOutputStream
TheFileOutputStream
thisOutputStream
is currently writing to.private String
fileBaseName
private long
maximumByteCount
-
Constructor Summary
Constructors Constructor Description SplitFileOutputStream(String fileBaseName, long maximumByteCount)
-
Method Summary
Modifier and Type Method Description void
close()
protected void
createNextFileOutputStream()
Create the following file in the sequence, and update thecurrentFileOutputStream
.long
getCurrentByteCount()
int
getCurrentFileCount()
String
getFileBaseName()
long
getMaximumByteCount()
void
write(int b)
-
Field Details
-
fileBaseName
-
currentByteCount
private long currentByteCount -
maximumByteCount
private long maximumByteCount -
currentFileCount
private int currentFileCount -
currentFileOutputStream
TheFileOutputStream
thisOutputStream
is currently writing to.
-
-
Constructor Details
-
SplitFileOutputStream
- Parameters:
fileBaseName
- The name that the files without the extension. If it is example, the created files will be example.c1, example.c2, and so on.maximumByteCount
- The number of bytes that should be written to a file before switching to the next one.
-
-
Method Details
-
createNextFileOutputStream
Create the following file in the sequence, and update thecurrentFileOutputStream
.- Throws:
IOException
- If for some reason the program cannot create the file.
-
write
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
getFileBaseName
- Returns:
- The name that the files without the extension. If it is example, the created files will be example.c1, example.c2, and so on.
-
getCurrentByteCount
public long getCurrentByteCount()- Returns:
- The number of bytes that have already been written to the current file.
-
getMaximumByteCount
public long getMaximumByteCount()- Returns:
- The number of bytes that should be written to a file before switching to the next one.
-
getCurrentFileCount
public int getCurrentFileCount()- Returns:
- The number of files that have already been created.
-