Package com.gengoai.io.resource
Class BaseResource
- java.lang.Object
-
- com.gengoai.io.resource.BaseResource
-
- All Implemented Interfaces:
Resource
,Serializable
- Direct Known Subclasses:
ByteArrayResource
,ClasspathResource
,EmptyResource
,FileResource
,InputStreamResource
,OutputStreamResource
,ReaderResource
,StdinResource
,StdoutResource
,StringResource
,URIResource
,URLResource
,WriterResource
,ZipResource
public abstract class BaseResource extends Object implements Resource, Serializable
Abstract base resource- 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 BaseResource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<File>
asFile()
Gets the resource as aFile
.Optional<URI>
asURI()
As uri optional.String
baseName()
Gets the name (file name or directory name) of this resource.boolean
canRead()
Returnstrue
if the resource is readable,false
if not.boolean
canWrite()
Returnstrue
if the resource is writable,false
if not.Resource
compressed()
Sets is compressed.protected InputStream
createInputStream()
Create input stream input stream.protected OutputStream
createOutputStream()
Create output stream output stream.String
descriptor()
Descriptor string.Charset
getCharset()
Gets the charset for reading and writing.InputStream
inputStream()
Opens an input stream over this resource.boolean
isCompressed()
Is compressed.boolean
isDirectory()
Is directory.OutputStream
outputStream()
Opens an output stream over this resource.String
path()
Gets path in the same mannar asFile.getPath()
Resource
setCharset(Charset charset)
Sets the charset for reading and writing.Resource
setCompression(Compression compression)
Sets the compression algorithm.Resource
setIsCompressed(boolean isCompressed)
Sets is compressed.String
toString()
Resource
uncompressed()
Uncompressed resource.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.gengoai.io.resource.Resource
append, append, asPath, asURL, childIterator, childIterator, copy, delete, delete, deleteOnExit, exists, forEach, getChild, getChildren, getChildren, getChildren, getChildren, getChildren, getParent, lines, mkdir, mkdirs, readBytes, reader, readLines, readObject, readToString, write, write, writeObject, writer
-
-
-
-
Method Detail
-
asFile
public Optional<File> asFile()
Description copied from interface:Resource
Gets the resource as aFile
.
-
baseName
public String baseName()
Description copied from interface:Resource
Gets the name (file name or directory name) of this resource.
-
canRead
public boolean canRead()
Description copied from interface:Resource
Returnstrue
if the resource is readable,false
if not.
-
canWrite
public boolean canWrite()
Description copied from interface:Resource
Returnstrue
if the resource is writable,false
if not.
-
compressed
public final Resource compressed()
Description copied from interface:Resource
Sets is compressed.- Specified by:
compressed
in interfaceResource
- Returns:
- the resource
-
createInputStream
protected InputStream createInputStream() throws IOException
Create input stream input stream.- Returns:
- the input stream
- Throws:
IOException
- the io exception
-
createOutputStream
protected OutputStream createOutputStream() throws IOException
Create output stream output stream.- Returns:
- the output stream
- Throws:
IOException
- the io exception
-
descriptor
public String descriptor()
Description copied from interface:Resource
Descriptor string.- Specified by:
descriptor
in interfaceResource
- Returns:
- The string representation of the resource with protocol
-
getCharset
public final Charset getCharset()
Description copied from interface:Resource
Gets the charset for reading and writing. The charset if not specified will be automatically determined during read.
- Specified by:
getCharset
in interfaceResource
- Returns:
- The charset used for writing and default when reading
-
inputStream
public InputStream inputStream() throws IOException
Description copied from interface:Resource
Opens an input stream over this resource.
- Specified by:
inputStream
in interfaceResource
- Returns:
- An input stream over this resource.
- Throws:
IOException
- the io exception
-
isCompressed
public final boolean isCompressed()
Description copied from interface:Resource
Is compressed.- Specified by:
isCompressed
in interfaceResource
- Returns:
- True if the resources is gzipped compressed
-
isDirectory
public boolean isDirectory()
Description copied from interface:Resource
Is directory.- Specified by:
isDirectory
in interfaceResource
- Returns:
- True if the resource is a directory
-
outputStream
public OutputStream outputStream() throws IOException
Description copied from interface:Resource
Opens an output stream over this resource.
- Specified by:
outputStream
in interfaceResource
- Returns:
- An output stream over this resource.
- Throws:
IOException
- the io exception
-
path
public String path()
Description copied from interface:Resource
Gets path in the same mannar asFile.getPath()
-
setCharset
public final Resource setCharset(Charset charset)
Description copied from interface:Resource
Sets the charset for reading and writing.
- Specified by:
setCharset
in interfaceResource
- Parameters:
charset
- The charset to use- Returns:
- the charset
-
setCompression
public Resource setCompression(Compression compression)
Description copied from interface:Resource
Sets the compression algorithm.- Specified by:
setCompression
in interfaceResource
- Parameters:
compression
- the compression algorithm- Returns:
- this Resource
-
setIsCompressed
public final Resource setIsCompressed(boolean isCompressed)
Description copied from interface:Resource
Sets is compressed.- Specified by:
setIsCompressed
in interfaceResource
- Parameters:
isCompressed
- the is compressed- Returns:
- the is compressed
-
uncompressed
public final Resource uncompressed()
Description copied from interface:Resource
Uncompressed resource.- Specified by:
uncompressed
in interfaceResource
- Returns:
- the resource
-
-