public final class FileMethods extends Object
Modifier and Type | Method and Description |
---|---|
static int |
copy(InputStream inputStream,
OutputStream outputStream,
io.toro.gloop.engine.GloopExecutionContext context)
Copies bytes from an
InputStream to an
OutputStream . |
static long |
copyLarge(InputStream inputStream,
OutputStream outputStream,
io.toro.gloop.engine.GloopExecutionContext context)
Copies bytes from a large (over 2GB)
InputStream to an
OutputStream . |
static io.toro.gloop.object.property.GloopModel |
getTextFileInputCursor(InputStream flatFileData,
String encoding,
String recordSeparator,
io.toro.gloop.engine.GloopExecutionContext context) |
static OutputStream |
outputStream(io.toro.gloop.engine.GloopExecutionContext context,
String file,
boolean mkDirs,
String... openOptions) |
static OutputStream |
packageOutputStream(io.toro.gloop.engine.GloopExecutionContext context,
String file,
String packageName,
boolean mkDirs,
String... openOptions) |
static OutputStream |
packageOutputStream(String file,
String packageName,
boolean mkDirs,
OpenOption... openOption)
Opens or creates a package file (if packageName is empty then currect Martini Package context is used),
returning an output stream that may be used to
write bytes to the file.
|
static String |
readAllContent(String resource,
String packageName)
Attempts to read a resource from the selected package context, returning an
String object to read
from the resource. |
static Stream<String> |
readContent(String resource,
String packageName)
Attempts to read a resource from the selected package context, returning an
Stream object to read
from the resource. |
static void |
readContent(String packageName,
String resource,
Closure<String> closure)
Attempts to read a resource from the selected package context and executing a
closure for every line of resource content
|
static io.toro.gloop.object.property.GloopModel |
readFileAsMultipart(String filePath,
String contentType) |
static io.toro.gloop.object.property.GloopModel |
readLines(String resource,
String packageName,
String encoding,
String lineSeparator,
io.toro.gloop.engine.GloopExecutionContext context) |
static io.toro.gloop.object.property.GloopModel |
readPackageFileAsMultipart(String resourceName,
String packageName,
String contentType) |
static Path |
resource(String resource,
String packageName)
Open a resource from the selected package context, returning an
Path to read from the resource. |
static InputStream |
resourceStream(String resource,
String packageName)
Open a resource from a specified package, returning an
InputStream
to read from the resource. |
static InputStream |
resourceStream(String resource,
String packageName,
io.toro.gloop.engine.GloopExecutionContext context)
Open a resource from a specified package, returning an
InputStream to read from the resource. |
static void |
write(byte[] data,
String file,
boolean mkDirs)
Writes bytes from a
byte[] to a destination specified. |
static void |
write(InputStream data,
String file,
boolean mkDirs)
Writes data from an InputStream to a destination specified.
|
static void |
writeToPackage(byte[] data,
String file,
String packageName,
boolean mkDirs)
WWrites bytes from a
byte[] to a destination in Martini Package |
static void |
writeToPackage(InputStream data,
String file,
String packageName,
boolean mkDirs)
Writes data from an InputStream to a destination in Martini Package
|
@GloopComment(value="Open a resource from a specified package, returning an InputStreamto read from the resource. The stream will not be buffered, and is not required to support the mark or reset methods. The stream will be safe for access by multiple concurrent threads.") public static final InputStream resourceStream(@GloopParameter(allowNull=false,value="Resource name. Example resource: conf/package.xml") String resource, @GloopParameter(value="If packageName is empty, current package context is selected") String packageName, io.toro.gloop.engine.GloopExecutionContext context) throws IOException
InputStream
to read from the resource. The stream
will not be buffered, and is not required to support the mark or reset methods. The stream will be safe for
access by multiple concurrent threads. packageName
- packageName
If packageName is empty, current package context is selectedresource
- the resourceName
ex. conf/package.xmlcontext
- gloop context
ex. conf/package.xmlIOException
- if an I/O error occursio.toro.martini.ipackage.exception.PackageRuntimeException
- if packageName is empty and current package context is not set properlypublic static final InputStream resourceStream(String resource, String packageName) throws IOException
InputStream
to read from the resource. The stream
will not be buffered, and is not required to support the mark or reset
methods. The stream will be safe for
access by multiple concurrent threads. packageName
- packageName
If packageName is empty, current package context is selectedresource
- the resourceName
ex. conf/package.xmlIOException
- if an I/O error occursio.toro.martini.ipackage.exception.PackageRuntimeException
- if packageName is empty and current package context is not set properly@GloopComment(value="Copies bytes from a large (over 2GB) InputStream to an OutputStream.\n\nThis method buffers the input internally, so there is no need to use a BufferedInputStream.\n\nThe buffer size is given by IOUtils.DEFAULT_BUFFER_SIZE.") public static long copyLarge(@GloopParameter(allowNull=false,value="input the InputStream to read from") InputStream inputStream, @GloopParameter(allowNull=false,value="output the OutputStreamto write to") OutputStream outputStream, io.toro.gloop.engine.GloopExecutionContext context) throws IOException
InputStream
to an
OutputStream
.
This method buffers the input internally, so there is no need to use a
BufferedInputStream
.
The buffer size is given by IOUtils.DEFAULT_BUFFER_SIZE
.
input
- the InputStream
to read fromoutput
- the OutputStream
to write toNullPointerException
- if the input or output is nullIOException
- if an I/O error occurs@GloopComment(value="Copies bytes from an InputStream to an OutputStream.\nThis method buffers the input internally, so there is no need to use a BufferedInputStream.\nLarge streams (over 2GB) will return a bytes copied value of -1 after the copy has completed since the correct number of bytes cannot be returned as an int. For large streams use the copyLarge(InputStream, OutputStream) method.") public static int copy(@GloopParameter(allowNull=false,value="input the InputStream to read from") InputStream inputStream, @GloopParameter(allowNull=false,value="output the OutputStreamto write to") OutputStream outputStream, io.toro.gloop.engine.GloopExecutionContext context) throws IOException
InputStream
to an
OutputStream
.
This method buffers the input internally, so there is no need to use a
BufferedInputStream
.
Large streams (over 2GB) will return a bytes copied value of
-1
after the copy has completed since the correct
number of bytes cannot be returned as an int. For large streams
use the copyLarge(InputStream, OutputStream)
method.
input
- the InputStream
to read fromoutput
- the OutputStream
to write toNullPointerException
- if the input or output is nullIOException
- if an I/O error occurspublic static OutputStream packageOutputStream(String file, String packageName, boolean mkDirs, OpenOption... openOption) throws IOException
This method opens or creates a file in exactly the manner specified
by the newByteChannel
method with the exception that the READ
option may not be present in the array of options. If no options are
present then this method works as if the CREATE
, TRUNCATE_EXISTING
,
and WRITE
options are present. In other
words, it opens the file for writing, creating the file if it doesn't
exist, or initially truncating an existing regular-file
to a size of 0
if it exists.
file
- filePath in stringpackageName
- Package to write the file in.
If packageName is empty, current package context is selectedmkDirs
- create the parent directories of the file flagopenOption
- options specifying how the file is openedIllegalArgumentException
- if options
contains an invalid combination of optionsUnsupportedOperationException
- if an unsupported option is specifiedIOException
- if an I/O error occursSecurityException
- In the case of the default provider, and a security manager is
installed, the checkWrite
method is invoked to check write access to the file. The checkDelete
method is
invoked to check delete access if the file is opened with the
DELETE_ON_CLOSE
option.@GloopComment(value="Opens or creates a package file (if packageName is empty then currect Martini Package context is used) returning an output stream that may be used to write bytes to the file. The resulting stream will not be buffered. The stream will be safe for access by multiple concurrent threads. Whether the returned stream is asynchronously closeable and/or interruptible is highly file system provider specific and therefore not specified.\n\nThis method opens or creates a file in exactly the manner specified by the newByteChannel method with the exception that the READ option may not be present in the array of options. If no options are present then this method works as if the CREATE, TRUNCATE_EXISTING, and WRITE options are present. In other words, it opens the file for writing, creating the file if it doesn\'t exist, or initially truncating an existing regular-file to a size of 0 if it exists.") public static OutputStream packageOutputStream(io.toro.gloop.engine.GloopExecutionContext context, @GloopParameter(allowNull=false,value="filePath in string") String file, @GloopParameter(value="Package to write the file in. If packageName is empty, current package context is selected") String packageName, @GloopParameter(allowNull=false,defaultValue="true",value="create the parent directories of the file. Default is true") boolean mkDirs, @GloopParameter(allowNull=true,value="options specifying how the file is opened",allowOtherValues=false,choices={"WRITE","APPEND","TRUNCATE_EXISTING","CREATE","CREATE_NEW","DELETE_ON_CLOSE","SPARSE","SYNC","DSYNC"}) String... openOptions) throws IOException
IOException
@GloopComment(value="Opens or creates a file, returning an output stream that may be used to write bytes to the file. The resulting stream will not be buffered. The stream will be safe for access by multiple concurrent threads. Whether the returned stream is asynchronously closeable and/or interruptible is highly file system provider specific and therefore not specified.\n\n This method opens or creates a file in exactly the manner specified by the newByteChannel method with the exception that the READ option may not be present in the array of options. If no options are present then this method works as if the CREATE, TRUNCATE_EXISTING, and WRITE options are present. In other words, it opens the file for writing, creating the file if it doesn\'t exist, or initially truncating an existing regular-file to a size of 0 if it exists.") public static OutputStream outputStream(io.toro.gloop.engine.GloopExecutionContext context, @GloopParameter(allowNull=false,value="filePath in string") String file, @GloopParameter(allowNull=false,defaultValue="true",value="create the parent directories of the file. Default is true") boolean mkDirs, @GloopParameter(allowNull=true,value="options specifying how the file is opened",allowOtherValues=false,choices={"WRITE","APPEND","TRUNCATE_EXISTING","CREATE","CREATE_NEW","DELETE_ON_CLOSE","SPARSE","SYNC","DSYNC"}) String... openOptions) throws IOException
IOException
@GloopComment(value="Writes bytes from a byte[] to a destination specified.") public static void write(@GloopParameter(allowNull=false,value="the byte array to write, do not modify during output") byte[] data, @GloopParameter(allowNull=false,value="filePath in string") String file, @GloopParameter(allowNull=false,defaultValue="true",value="create the parent directories of the file. Default is true") boolean mkDirs) throws IOException
byte[]
to a destination specified.data
- the byte array to write, do not modify during output,
null ignoredfile
- the location to write the filemkDirs
- create the parent directories of the file flagNullPointerException
- if output is nullIOException
- if an I/O error occurs@GloopComment(value="Writes data from an InputStream to a destination specified.") public static void write(@GloopParameter(allowNull=false,value="the inputstream to read from") InputStream data, @GloopParameter(allowNull=false,value="filePath in string") String file, @GloopParameter(allowNull=false,defaultValue="true",value="create the parent directories of the file. Default is true") boolean mkDirs) throws IOException
data
- the inputstream to read fromfile
- the location to write the filemkDirs
- create the parent directories of the file flagNullPointerException
- if output is nullIOException
- if an I/O error occurs@GloopComment(value="Writes bytes from a byte[] to a destination in Martini Package") public static void writeToPackage(@GloopParameter(allowNull=false,value="the byte array to write, do not modify during output") byte[] data, @GloopParameter(allowNull=false,value="filePath in string") String file, @GloopParameter(value="Package to write the file in. If packageName is empty, current package context is selected") String packageName, @GloopParameter(allowNull=false,defaultValue="true",value="create the parent directories of the file. Default is true") boolean mkDirs) throws IOException
byte[]
to a destination in Martini Packagedata
- the byte array to write, do not modify during output, null ignoredfile
- the location to write the filepackageName
- Package to write the file in. If packageName is empty, current package context is selectedmkDirs
- create the parent directories of the file flagNullPointerException
- if output is nullIOException
- if an I/O error occurs@GloopComment(value="Writes data from an InputStream to a destination in Martini Package") public static void writeToPackage(@GloopParameter(allowNull=false,value="the inputstream to read from") InputStream data, @GloopParameter(allowNull=false,value="filePath in string") String file, @GloopParameter(value="Package to write the file in. If packageName is empty, current package context is selected") String packageName, @GloopParameter(allowNull=false,defaultValue="true",value="create the parent directories of the file. Default is true") boolean mkDirs) throws IOException
data
- the inputstream to read fromfile
- the location to write the filepackageName
- Package to write the file in. If packageName is empty, current package context is selectedmkDirs
- create the parent directories of the file flagNullPointerException
- if output is nullIOException
- if an I/O error occurs@GloopComment(value="Open a resource from the selected package context, returning a Path to read from the resource. If packageName is empty, current package context is selected") public static final Path resource(@GloopParameter(allowNull=false,value="Resource name. Example resource: conf/package.xml") String resource, @GloopParameter(value="If packageName is empty, current package context is selected") String packageName) throws IOException
Path
to read from the resource. packageName
- packageName
If packageName is empty, current package context is selectedresource
- the resourceName
ex. conf/package.xmlIOException
- if an I/O error occursio.toro.martini.ipackage.exception.PackageRuntimeException
- if packageName is empty and current package context is not set properly@GloopComment(value="Attempts to read a resource from the selected package context, returning a Stream<String> object to read from the resource. This method does not read all lines, but instead populates lazily as the stream is consumed. If packageName is empty, current package context is selected") public static final Stream<String> readContent(@GloopParameter(allowNull=false,value="Resource name. Example resource: conf/package.xml") String resource, @GloopParameter(value="If packageName is empty, current package context is selected") String packageName) throws IOException
Stream
object to read
from the resource. this method does not read all lines, but instead populates lazily as the stream is consumed.
packageName
- packageName
If packageName is empty, current package context is selectedresource
- the resourceName
ex. conf/package.xmlIOException
- if an I/O error occursio.toro.martini.ipackage.exception.PackageRuntimeException
- if packageName is empty and current package context is not set properlypublic static final void readContent(String packageName, String resource, Closure<String> closure) throws IOException
packageName
- packageName
If packageName is empty, current package context is selectedresource
- the resourceName
ex. conf/package.xmlIOException
- if an I/O error occursio.toro.martini.ipackage.exception.PackageRuntimeException
- if packageName is empty and current package context is not set properly@GloopComment(value="Attempts to read a resource from the selected package context, returning a String object to read from the resource. If packageName is empty, current package context is selected") public static final String readAllContent(@GloopParameter(allowNull=false,value="Resource name. Example resource: conf/package.xml") String resource, @GloopParameter(value="If packageName is empty, current package context is selected") String packageName) throws IOException
String
object to read
from the resource.
packageName
- packageName
If packageName is empty, current package context is selectedresource
- the resourceName
ex. conf/package.xmlIOException
- if an I/O error occursio.toro.martini.ipackage.exception.PackageRuntimeException
- if packageName is empty and current package context is not set properly@GloopComment(value="Read an inputstream and return a gloop cursorobject to read from the resource. If packageName is empty, current package context is selected") @GloopObjectParameter(value="output{\n output{\n linesInputCursor[]\n }\n}") public static io.toro.gloop.object.property.GloopModel getTextFileInputCursor(@GloopParameter(allowNull=false,value="Resource inputstream") InputStream flatFileData, @GloopParameter(value="Encoding",defaultValue="UTF-8") String encoding, @GloopParameter(value="The record separator",defaultValue="\n") String recordSeparator, io.toro.gloop.engine.GloopExecutionContext context)
@GloopComment(value="Wrap a file path and return a Mutlipart GloopModel. If file does not exists expect null return value") @GloopObjectParameter(value="output{\n multipartFile#io.toro.martini.http.MultipartFile{\n }\n}") public static io.toro.gloop.object.property.GloopModel readFileAsMultipart(@GloopParameter(allowNull=false,value="File path") String filePath, @GloopParameter(allowNull=false,value="Content type of file that conforms HTTP specifications. See http://tools.ietf.org/html/rfc7231#section-3.1.1.1 ") String contentType)
@GloopComment(value="Find a file in the selected Martini Package and wraps it in a Mutlipart GloopModel. If file does not exists expect null return value") @GloopObjectParameter(value="output{\n multipartFile#io.toro.martini.http.MultipartFile{\n }\n}") public static io.toro.gloop.object.property.GloopModel readPackageFileAsMultipart(@GloopParameter(allowNull=false,value="Resource name. Example resource: conf/package.xml") String resourceName, @GloopParameter(value="If packageName is empty, current package context is selected") String packageName, @GloopParameter(allowNull=false,value="Content type of file that conforms HTTP specifications. See http://tools.ietf.org/html/rfc7231#section-3.1.1.1 ") String contentType)
@GloopComment(value="Read a resource file residing in a Martini Package and return a Gloop Cursor") @GloopObjectParameter(value="output{\n output{\n linesInputCursor[]\n }\n}") public static io.toro.gloop.object.property.GloopModel readLines(@GloopParameter(allowNull=false,value="resource file name in the Martini Package") String resource, @GloopParameter(value="If packageName is empty, current package context is selected") String packageName, @GloopParameter(value="Encoding",defaultValue="UTF-8") String encoding, @GloopParameter(value="The record separator",defaultValue="\n") String lineSeparator, io.toro.gloop.engine.GloopExecutionContext context) throws IOException
IOException
Copyright © 2019. All rights reserved.