Package com.gengoai.io.resource
Class StringResource
- java.lang.Object
-
- com.gengoai.io.resource.BaseResource
-
- com.gengoai.io.resource.StringResource
-
- All Implemented Interfaces:
NonTraversableResource
,Resource
,Serializable
public class StringResource extends BaseResource implements NonTraversableResource
A resource that wraps a String.
- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.gengoai.io.resource.Resource
Resource.Deserializer
-
-
Field Summary
-
Fields inherited from interface com.gengoai.io.resource.Resource
ALL_FILE_PATTERN
-
-
Constructor Summary
Constructors Constructor Description StringResource()
Instantiates a new string resource.StringResource(String resource)
Creates a Resource that is a String.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Resource
append(byte[] byteArray)
Appends the given byte array content to the resource.Resource
append(String content)
Appends the given string content to the resource.protected InputStream
createInputStream()
Create input stream input stream.protected OutputStream
createOutputStream()
Create output stream output stream.boolean
equals(Object obj)
boolean
exists()
Exists boolean.int
hashCode()
MStream<String>
lines()
Creates anMStream
over the lines in the resource.byte[]
readBytes()
Reads the resource into an array of bytes.Reader
reader()
Opens a reader using guessing the encoding and falling back to the default on the resource.List<String>
readLines()
Reads the complete resource in as text breaking it into lines based on the newline characterString
readToString()
Reads in the resource as a String using UTF-8.-
Methods inherited from class com.gengoai.io.resource.BaseResource
asFile, asURI, baseName, canRead, canWrite, compressed, descriptor, getCharset, inputStream, isCompressed, isDirectory, outputStream, path, setCharset, setCompression, setIsCompressed, toString, uncompressed
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.gengoai.io.resource.NonTraversableResource
childIterator, childIterator, getChild, getChildren, getChildren, getChildren, getChildren, getChildren, getParent
-
Methods inherited from interface com.gengoai.io.resource.Resource
asFile, asPath, asURI, asURL, baseName, canRead, canWrite, compressed, copy, delete, delete, deleteOnExit, descriptor, forEach, getCharset, inputStream, isCompressed, isDirectory, mkdir, mkdirs, outputStream, path, readObject, setCharset, setCompression, setIsCompressed, uncompressed, write, write, writeObject, writer
-
-
-
-
Constructor Detail
-
StringResource
public StringResource()
Instantiates a new string resource.
-
StringResource
public StringResource(String resource)
Creates a Resource that is a String.
- Parameters:
resource
- The string contents.
-
-
Method Detail
-
readToString
public String readToString() throws IOException
Description copied from interface:Resource
Reads in the resource as a String using UTF-8.
- Specified by:
readToString
in interfaceResource
- Returns:
- A string representing the contents of the file.
- Throws:
IOException
- the io exception
-
readBytes
public byte[] readBytes() throws IOException
Description copied from interface:Resource
Reads the resource into an array of bytes.
- Specified by:
readBytes
in interfaceResource
- Returns:
- An array of bytes representing the content of the resource.
- Throws:
IOException
- the io exception
-
reader
public Reader reader() throws IOException
Description copied from interface:Resource
Opens a reader using guessing the encoding and falling back to the default on the resource.- Specified by:
reader
in interfaceResource
- Returns:
- A reader
- Throws:
IOException
- the io exception
-
readLines
public List<String> readLines() throws IOException
Description copied from interface:Resource
Reads the complete resource in as text breaking it into lines based on the newline character- Specified by:
readLines
in interfaceResource
- Returns:
- A list of string representing the contents of the file.
- Throws:
IOException
- the io exception
-
append
public Resource append(String content) throws IOException
Description copied from interface:Resource
Appends the given string content to the resource.
- Specified by:
append
in interfaceResource
- Parameters:
content
- The content to append- Returns:
- the resource
- Throws:
IOException
- the io exception
-
append
public Resource append(byte[] byteArray) throws IOException
Description copied from interface:Resource
Appends the given byte array content to the resource.
- Specified by:
append
in interfaceResource
- Parameters:
byteArray
- The content to append- Returns:
- the resource
- Throws:
IOException
- the io exception
-
exists
public boolean exists()
Description copied from interface:Resource
Exists boolean.
-
lines
public MStream<String> lines() throws IOException
Description copied from interface:Resource
Creates anMStream
over the lines in the resource.- Specified by:
lines
in interfaceResource
- Returns:
- the stream of lines
- Throws:
IOException
- Something went wrong reading from the resource
-
createInputStream
protected InputStream createInputStream() throws IOException
Description copied from class:BaseResource
Create input stream input stream.- Overrides:
createInputStream
in classBaseResource
- Returns:
- the input stream
- Throws:
IOException
- the io exception
-
createOutputStream
protected OutputStream createOutputStream() throws IOException
Description copied from class:BaseResource
Create output stream output stream.- Overrides:
createOutputStream
in classBaseResource
- Returns:
- the output stream
- Throws:
IOException
- the io exception
-
-