Interface Target
- All Known Implementing Classes:
ByteArrayTarget,FileTarget,OutputStreamTarget
public interface Target
Abstracts away access to an on-demand OutputStream over a given resource. Most
implementations are able to provide repeated access to the underlying resource.
However, not all resources can be reused and multiple calls to
getOutputStream() will fail if isReusable() returns false.- Author:
- jbanes
-
Method Summary
Modifier and TypeMethodDescriptionReturns anOutputStreamover the underlying resourcedefault booleanReturns true if the target is reusable.default booleanisUsed()Returns true if the OutputStream has already been accessed and another attempt to accessgetOutputStream()will fail.default voidwrite(byte[] data) Convenience method for writing data to a file.default voidwriteString(String data) Convenience method for writing string data to a file in UTF-8 format.default voidwriteString(String data, String encoding) Convenience method for writing string data to a file.
-
Method Details
-
getOutputStream
OutputStream getOutputStream()Returns anOutputStreamover the underlying resource- Returns:
- an OutputStream
-
isReusable
default boolean isReusable()Returns true if the target is reusable. The default implementation returns true, so this must be overridden if your implementation is not reusable.- Returns:
- true
-
isUsed
default boolean isUsed()Returns true if the OutputStream has already been accessed and another attempt to accessgetOutputStream()will fail. The default implementation returns false, so this must be overridden if your implementation is not reusable.- Returns:
- false
-
writeString
Convenience method for writing string data to a file in UTF-8 format. This is useful for quickly serializing in-memory data to a file, typically generated information that is of use to a user.- Parameters:
data- the string to write
-
writeString
Convenience method for writing string data to a file. This is useful for quickly serializing in-memory data to a file, typically generated information that is of use to a user.- Parameters:
data- the string to writeencoding- the desired character encoding
-
write
default void write(byte[] data) Convenience method for writing data to a file. This is useful for quickly serializing in-memory data to a file, typically generated information that is of use to a user.- Parameters:
data- a byte array of the data to write
-