Package com.gengoai.io.resource
Class URLResource
- java.lang.Object
-
- com.gengoai.io.resource.BaseResource
-
- com.gengoai.io.resource.URLResource
-
- All Implemented Interfaces:
Resource
,Serializable
public class URLResource extends BaseResource
A
Resource
wrapper for a URL.- 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 URLResource(String url)
Instantiates a new uRL resource.URLResource(URL url)
-
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.Optional<File>
asFile()
Gets the resource as aFile
.Optional<URI>
asURI()
As uri optional.Optional<URL>
asURL()
Gets the resource as aURL
.String
baseName()
Gets the name (file name or directory name) of this resource.InputStream
createInputStream()
Create input stream input stream.OutputStream
createOutputStream()
Create output stream output stream.String
descriptor()
Descriptor string.boolean
equals(Object o)
boolean
exists()
Exists boolean.Resource
getChild(String relativePath)
Creates a new Resource that is relative to this resource.int
getConnectionTimeOut()
Resource
getParent()
Gets parent.String
getUserAgent()
int
hashCode()
MStream<String>
lines()
Creates anMStream
over the lines in the resource.String
path()
Gets path in the same mannar asFile.getPath()
List<String>
readLines()
Reads the complete resource in as text breaking it into lines based on the newline charactervoid
setConnectionTimeOut(int connectionTimeOut)
Sets the amount of time to wait in connecting to the host before giving upvoid
setUserAgent(String userAgent)
Sets The user agent string to pass along to the web server-
Methods inherited from class com.gengoai.io.resource.BaseResource
canRead, canWrite, compressed, getCharset, inputStream, isCompressed, isDirectory, outputStream, 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.Resource
asPath, childIterator, childIterator, copy, delete, delete, deleteOnExit, forEach, getChildren, getChildren, getChildren, getChildren, getChildren, mkdir, mkdirs, readBytes, reader, readObject, readToString, write, write, writeObject, writer
-
-
-
-
Constructor Detail
-
URLResource
public URLResource(String url) throws MalformedURLException
Instantiates a new uRL resource.- Parameters:
url
- the url- Throws:
MalformedURLException
- the malformed url exception
-
URLResource
public URLResource(URL url)
-
-
Method Detail
-
descriptor
public String descriptor()
Description copied from interface:Resource
Descriptor string.- Specified by:
descriptor
in interfaceResource
- Overrides:
descriptor
in classBaseResource
- Returns:
- The string representation of the resource with protocol
-
asFile
public Optional<File> asFile()
Description copied from interface:Resource
Gets the resource as aFile
.- Specified by:
asFile
in interfaceResource
- Overrides:
asFile
in classBaseResource
- Returns:
- A
File
representing the resource.
-
asURI
public Optional<URI> asURI()
Description copied from interface:Resource
As uri optional.- Specified by:
asURI
in interfaceResource
- Overrides:
asURI
in classBaseResource
- Returns:
- the optional
-
path
public String path()
Description copied from interface:Resource
Gets path in the same mannar asFile.getPath()
- Specified by:
path
in interfaceResource
- Overrides:
path
in classBaseResource
- Returns:
- The full path to the resource including name
-
baseName
public String baseName()
Description copied from interface:Resource
Gets the name (file name or directory name) of this resource.- Specified by:
baseName
in interfaceResource
- Overrides:
baseName
in classBaseResource
- Returns:
- The name of the file or directory
-
asURL
public Optional<URL> asURL()
Description copied from interface:Resource
Gets the resource as aURL
.- Returns:
- A
URL
representing the resource.
-
getChild
public Resource getChild(String relativePath)
Description copied from interface:Resource
Creates a new Resource that is relative to this resource.
- Parameters:
relativePath
- The relative path for the new resource.- Returns:
- A new resource that is relative to this resource.
-
getParent
public Resource getParent()
Description copied from interface:Resource
Gets parent.- Returns:
- The parent resource (directory for file, parent directory for a directory)
-
append
public Resource append(String content) throws IOException
Description copied from interface:Resource
Appends the given string content to the resource.
- 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.
- 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.- Returns:
- True if the resource exists, False if the resource does not exist.
-
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- Returns:
- A list of string representing the contents of the file.
- Throws:
IOException
- the io exception
-
lines
public MStream<String> lines() throws IOException
Description copied from interface:Resource
Creates anMStream
over the lines in the resource.- Returns:
- the stream of lines
- Throws:
IOException
- Something went wrong reading from the resource
-
createInputStream
public 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
public 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
-
getUserAgent
public String getUserAgent()
- Returns:
- The user agent string to pass along to the web server
-
setUserAgent
public void setUserAgent(String userAgent)
Sets The user agent string to pass along to the web server- Parameters:
userAgent
- the user agent
-
getConnectionTimeOut
public int getConnectionTimeOut()
- Returns:
- the amount of time to wait in connecting to the host before giving up
-
setConnectionTimeOut
public void setConnectionTimeOut(int connectionTimeOut)
Sets the amount of time to wait in connecting to the host before giving up- Parameters:
connectionTimeOut
- The connectionTimeOut
-
-