Javadoc exceptions, remove whitespace, remove dead comments, rename
param.
public class DeferredFileOutputStream
extends ThresholdingOutputStream
{
- // ----------------------------------------------------------- Data members
-
/**
* The output stream to which data will be written prior to the threshold
*/
private ByteArrayOutputStream memoryOutputStream;
-
/**
* The output stream to which data will be written at any given time. This
* will always be one of <code>memoryOutputStream</code> or
*/
private OutputStream currentOutputStream;
-
/**
* The file to which output will be directed if the threshold is exceeded.
*/
*/
private final File directory;
-
/**
* True when close() has been called successfully.
*/
private boolean closed = false;
- // ----------------------------------------------------------- Constructors
-
-
/**
* Constructs an instance of this class which will trigger an event at the specified threshold, and save data to a
* file beyond that point. The initial buffer size will default to
@@ -185,10 +177,6 @@ private DeferredFileOutputStream(final int threshold, final File outputFile, fin
currentOutputStream = memoryOutputStream;
}
-
- // --------------------------------------- ThresholdingOutputStream methods
-
-
/**
* Returns the current output stream. This may be memory based or disk
* based, depending on the current state with respect to the threshold.
@@ -203,7 +191,6 @@ protected OutputStream getStream() throws IOException
return currentOutputStream;
}
-
/**
* Switches the underlying output stream from a memory based stream to one
* that is backed by disk. This is the point at which we realize that too
@@ -230,10 +217,6 @@ protected void thresholdReached() throws IOException
memoryOutputStream = null;
}
-
- // --------------------------------------------------------- Public methods
-
-
/**
* Determines whether or not the data for this output stream has been
* retained in memory.
@@ -246,7 +229,6 @@ public boolean isInMemory()
return !isThresholdExceeded();
}
-
/**
* Returns the data for this output stream as an array of bytes, assuming
* that the data has been retained in memory. If the data was written to
@@ -257,13 +239,8 @@ public boolean isInMemory()
*/
public byte[] getData()
{
- if (memoryOutputStream != null)
- {
- return memoryOutputStream.toByteArray();
+ return memoryOutputStream != null ? memoryOutputStream.toByteArray() : null;
}
- return null;
- }
-
/**
* Returns either the output file specified in the constructor or
@@ -284,7 +261,6 @@ public File getFile()
return outputFile;
}
-
/**
* Closes underlying output stream, and mark this as closed
*
@@ -297,15 +273,15 @@ public void close() throws IOException
closed = true;
}
-
/**
* Writes the data from this output stream to the specified output stream,
* after it has been closed.
*
- * @param out output stream to write to.
+ * @param outputStream output stream to write to.
+ * @throws NullPointerException if the OutputStream is {@code null}.
* @throws IOException if this stream is not yet closed or an error occurs.
*/
- public void writeTo(final OutputStream out) throws IOException
+ public void writeTo(final OutputStream outputStream) throws IOException
{
// we may only need to check if this is closed if we are working with a file
// but we should force the habit of closing whether we are working with
@@ -315,10 +291,10 @@ public void writeTo(final OutputStream out) throws IOException
}
if (isInMemory()) {
- memoryOutputStream.writeTo(out);
+ memoryOutputStream.writeTo(outputStream);
} else {
try (FileInputStream fis = new FileInputStream(outputFile)) {
- IOUtils.copy(fis, out);
+ IOUtils.copy(fis, outputStream);
}
}
}
