Package com.wavemaker.commons.io
Class AbstractFileContent
- java.lang.Object
-
- com.wavemaker.commons.io.AbstractFileContent
-
- All Implemented Interfaces:
FileContent
public abstract class AbstractFileContent extends java.lang.Object implements FileContent
Abstract base class forFileContent.
-
-
Constructor Summary
Constructors Constructor Description AbstractFileContent()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]asBytes()Return the contents of the file as a new byte array.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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.wavemaker.commons.io.FileContent
asInputStream, asOutputStream, asOutputStream
-
-
-
-
Method Detail
-
asReader
public java.io.Reader asReader()
Description copied from interface:FileContentReturn 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.- Specified by:
asReaderin interfaceFileContent- Returns:
- the file contents
Reader
-
asString
public java.lang.String asString()
Description copied from interface:FileContentReturn the contents of the file as a String. This method should be used with caution if working with large files.- Specified by:
asStringin interfaceFileContent- Returns:
- the contents as a String
-
asBytes
public byte[] asBytes()
Description copied from interface:FileContentReturn the contents of the file as a new byte array. This method should be used with caution if working with large files.- Specified by:
asBytesin interfaceFileContent- Returns:
- the contents as a new byte array.
-
copyTo
public void copyTo(java.io.OutputStream outputStream)
Description copied from interface:FileContentCopy the contents of the file to another stream, closing the stream when complete.- Specified by:
copyToin interfaceFileContent
-
copyTo
public void copyTo(java.io.Writer writer)
Description copied from interface:FileContentCopy the contents of the file to another writer, closing the writer when complete.- Specified by:
copyToin interfaceFileContent
-
asWriter
public java.io.Writer asWriter()
Description copied from interface:FileContentReturn aWriterthat can be used to write file contents. The writer should be closed by the caller. When possible, consider using theFileContent.write(Reader)method instead to ensure that streams are closed.- Specified by:
asWriterin interfaceFileContent- Returns:
- The writer
-
asWriter
public java.io.Writer asWriter(boolean append)
- Specified by:
asWriterin interfaceFileContent- 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 theFileContent.write(Reader)method instead to ensure that streams are closed.- Returns:
- The writer
-
write
public void write(File file)
Description copied from interface:FileContentWrite the contents of the specified file to this file.- Specified by:
writein interfaceFileContent- Parameters:
file- the file to copy.
-
write
public void write(java.io.InputStream inputStream)
Description copied from interface:FileContentWrite the contents of the specified output stream to this file, closing the stream when complete.- Specified by:
writein interfaceFileContent- Parameters:
inputStream- the input stream to write
-
write
public void write(java.io.Reader reader)
Description copied from interface:FileContentWrite the contents of the specified reader to this file, closing the reader when complete.- Specified by:
writein interfaceFileContent- Parameters:
reader- the reader to write
-
write
public void write(java.lang.String string)
Description copied from interface:FileContentWrite the contents of the specified string to this file.- Specified by:
writein interfaceFileContent- Parameters:
string- the string contents
-
-