Package com.wavemaker.commons.io
Interface FileContent
-
- All Known Implementing Classes:
AbstractFileContent
public interface FileContentProvides access toFilecontent in a variety of ways.- See Also:
File
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description byte[]asBytes()Return the contents of the file as a new byte array.java.io.InputStreamasInputStream()Return anInputStreamthat can be used to access file contents.java.io.OutputStreamasOutputStream()Return anOutputStreamthat can be used to write file contents.java.io.OutputStreamasOutputStream(boolean append)java.io.ReaderasReader()Return aReaderthat can be used to access file contents.java.lang.StringasString()Return the contents of the file as a String.java.io.WriterasWriter()Return aWriterthat can be used to write file contents.java.io.WriterasWriter(boolean append)voidcopyTo(java.io.OutputStream outputStream)Copy the contents of the file to another stream, closing the stream when complete.voidcopyTo(java.io.Writer writer)Copy the contents of the file to another writer, closing the writer when complete.voidwrite(File file)Write the contents of the specified file to this file.voidwrite(java.io.InputStream inputStream)Write the contents of the specified output stream to this file, closing the stream when complete.voidwrite(java.io.Reader reader)Write the contents of the specified reader to this file, closing the reader when complete.voidwrite(java.lang.String string)Write the contents of the specified string to this file.
-
-
-
Method Detail
-
asInputStream
java.io.InputStream asInputStream()
Return anInputStreamthat can be used to access file contents. This method can be called multiple times if required. The stream should be closed by the caller.- Returns:
- The file contents
InputStream
-
asReader
java.io.Reader asReader()
Return aReaderthat can be used to access file contents. This method can be called multiple times if required. The reader should be closed by the caller.- Returns:
- the file contents
Reader
-
asString
java.lang.String asString()
Return the contents of the file as a String. This method should be used with caution if working with large files.- Returns:
- the contents as a String
-
asBytes
byte[] asBytes()
Return the contents of the file as a new byte array. This method should be used with caution if working with large files.- Returns:
- the contents as a new byte array.
-
copyTo
void copyTo(java.io.OutputStream outputStream)
Copy the contents of the file to another stream, closing the stream when complete.
-
copyTo
void copyTo(java.io.Writer writer)
Copy the contents of the file to another writer, closing the writer when complete.
-
asOutputStream
java.io.OutputStream asOutputStream()
Return anOutputStreamthat can be used to write file contents. The output stream should be closed by the caller. When possible, consider using thewrite(InputStream)method instead to ensure that streams are closed.- Returns:
- The output stream
-
asOutputStream
java.io.OutputStream asOutputStream(boolean append)
- Parameters:
append- iftrue, open the file OutputStream in append mode, otherwise as new file Return anOutputStreamthat can be used to write file contents. The output stream should be closed by the caller. When possible, consider using thewrite(InputStream)method instead to ensure that streams are closed.- Returns:
- The output stream
-
asWriter
java.io.Writer asWriter()
Return aWriterthat can be used to write file contents. The writer should be closed by the caller. When possible, consider using thewrite(Reader)method instead to ensure that streams are closed.- Returns:
- The writer
-
asWriter
java.io.Writer asWriter(boolean append)
- Parameters:
append- iftrue, open the file Writer in append mode, otherwise as new file Return aWriterthat can be used to write file contents with append mode. The writer should be closed by the caller. When possible, consider using thewrite(Reader)method instead to ensure that streams are closed.- Returns:
- The writer
-
write
void write(File file)
Write the contents of the specified file to this file.- Parameters:
file- the file to copy.
-
write
void write(java.io.InputStream inputStream)
Write the contents of the specified output stream to this file, closing the stream when complete.- Parameters:
inputStream- the input stream to write
-
write
void write(java.io.Reader reader)
Write the contents of the specified reader to this file, closing the reader when complete.- Parameters:
reader- the reader to write
-
write
void write(java.lang.String string)
Write the contents of the specified string to this file.- Parameters:
string- the string contents
-
-