Class CmdlineUtils
IO is accessed through a CmdlineContext
acquired with ServiceLoader
. A single service registration is
expected.
-
Method Summary
Modifier and TypeMethodDescriptionstatic InputStream
autoGzip
(InputStream in) Deprecated, for removal: This API element is subject to removal in a future version.Detect gzippedInputStream
.static void
exit
(int status) Deprecated, for removal: This API element is subject to removal in a future version.Terminate execution with given status code.static PrintStream
getErr()
Deprecated, for removal: This API element is subject to removal in a future version.Get stderr to use.static InputStream
getIn()
Deprecated, for removal: This API element is subject to removal in a future version.Get stdin to use.static PrintStream
getOut()
Deprecated, for removal: This API element is subject to removal in a future version.Get stdout to use.static InputStream
inputStreamFromLocation
(String location) Deprecated, for removal: This API element is subject to removal in a future version.Create InputStream from not nullable location.static InputStream
inputStreamFromLocation
(String location, boolean autoGzip) Deprecated, for removal: This API element is subject to removal in a future version.Create InputStream from not nullable location.static Optional<InputStream>
inputStreamFromNullableLocation
(String location) Deprecated, for removal: This API element is subject to removal in a future version.Create in input stream from nullable location.static Optional<InputStream>
inputStreamFromNullableLocation
(String location, boolean autoGzip) Deprecated, for removal: This API element is subject to removal in a future version.Create in input stream from nullable location.static boolean
isFileExists
(String name) Deprecated, for removal: This API element is subject to removal in a future version.Check if a file exists.static CloseableLineIterator
lineIteratorFromLocation
(String location) Deprecated, for removal: This API element is subject to removal in a future version.Create anIterator
that can be closed from a not nullable location.static CloseableLineIterator
lineIteratorFromLocation
(String location, boolean autoGzip) Deprecated, for removal: This API element is subject to removal in a future version.Create anIterator
that can be closed from a not nullable location.static ObjectInputStream
objectInputStreamFromLocation
(String location) Deprecated, for removal: This API element is subject to removal in a future version.Create ObjectInputStream from a not nullable location.static ObjectInputStream
objectInputStreamFromLocation
(String location, boolean autoGzip) Deprecated, for removal: This API element is subject to removal in a future version.Create ObjectInputStream from a not nullable location.static Optional<ObjectInputStream>
objectInputStreamFromNullableLocation
(String location) Deprecated, for removal: This API element is subject to removal in a future version.Create in object input stream from nullable location.static ObjectOutputStream
objectOutputStreamFromLocation
(String location) Deprecated, for removal: This API element is subject to removal in a future version.ObjectOutputStream from a location.static Optional<ObjectOutputStream>
objectOutputStreamFromNullableLocation
(String location) Deprecated, for removal: This API element is subject to removal in a future version.ObjectOutputStream from a nullable location.static InputStream
openUrlStream
(String spec) Deprecated, for removal: This API element is subject to removal in a future version.Open an URL connection.static OutputStream
outputStreamFromLocation
(String location) Deprecated, for removal: This API element is subject to removal in a future version.OutputStream from a location.static PrintStream
printStreamFromLocation
(String location) Deprecated, for removal: This API element is subject to removal in a future version.PrintStream from a location.static Optional<PrintStream>
printStreamFromNullableLocation
(String location) Deprecated, for removal: This API element is subject to removal in a future version.PrintStream from a nullable location.static String
stringFromLocation
(String location) Deprecated, for removal: This API element is subject to removal in a future version.Read the contents of a location into a String.static String
stringFromLocation
(String location, boolean autoGzip) Deprecated, for removal: This API element is subject to removal in a future version.Read the contents of a location into a String.stringFromNullableLocation
(String location) Deprecated, for removal: This API element is subject to removal in a future version.Read the contents of a location when it is not null.stringFromNullableLocation
(String location, boolean autoGzip) Deprecated, for removal: This API element is subject to removal in a future version.Read the contents of a location when it is not null.
-
Method Details
-
autoGzip
Deprecated, for removal: This API element is subject to removal in a future version.Detect gzippedInputStream
.Checks
GZIPInputStream.GZIP_MAGIC
and wraps input when match found. Further validity check is not done. See http://stackoverflow.com/questions/1080381/gzipinputstream-reading-line-by-line.- Parameters:
in
- Input- Returns:
- Input wrapped in
GZIPInputStream
whenGZIPInputStream.GZIP_MAGIC
match, otherwise input, possibly wrapped in aBufferedInputStream
. - Throws:
IOException
- Propagated
-
getOut
Deprecated, for removal: This API element is subject to removal in a future version.Get stdout to use.- Returns:
- StdOut specified by the default command line context
-
getErr
Deprecated, for removal: This API element is subject to removal in a future version.Get stderr to use.- Returns:
- StdErr specified by the default command line context
-
getIn
Deprecated, for removal: This API element is subject to removal in a future version.Get stdin to use.- Returns:
- StdIn specified by the default command line context
-
isFileExists
Deprecated, for removal: This API element is subject to removal in a future version.Check if a file exists.- Parameters:
name
- Name to delegate
-
openUrlStream
Deprecated, for removal: This API element is subject to removal in a future version.Open an URL connection.- Parameters:
spec
- URL spec- Returns:
- Stream
- Throws:
IOException
- Propagated
-
exit
public static void exit(int status) Deprecated, for removal: This API element is subject to removal in a future version.Terminate execution with given status code.By default, implementation calls
System.exit(int)
. Test time implementations might decide to change this behavior.- Parameters:
status
- Status code; by convention nonzero status code indicates abnormal termination
-
inputStreamFromLocation
Deprecated, for removal: This API element is subject to removal in a future version.Create InputStream from not nullable location.- Parameters:
location
- File name or "-" for stdin.- Returns:
- Input stream representing given location. Returned input stream should be closed after usage.
- Throws:
FileNotFoundException
- thrown byFileInputStream(java.lang.String)
-
inputStreamFromLocation
public static InputStream inputStreamFromLocation(String location, boolean autoGzip) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.Create InputStream from not nullable location.- Parameters:
location
- File name or "-" for stdin.autoGzip
- Wrap returned stream throughautoGzip(java.io.InputStream)
.- Returns:
- Input stream representing given location. Returned input stream should be closed after usage.
- Throws:
IOException
- propagated
-
objectInputStreamFromLocation
public static ObjectInputStream objectInputStreamFromLocation(String location, boolean autoGzip) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.Create ObjectInputStream from a not nullable location.- Parameters:
location
- File name or "-" for stdinautoGzip
- Wrap returned stream throughautoGzip(java.io.InputStream)
.- Returns:
ObjectInputStream
to be used- Throws:
IOException
- re-thrown
-
objectInputStreamFromLocation
Deprecated, for removal: This API element is subject to removal in a future version.Create ObjectInputStream from a not nullable location.- Parameters:
location
- File name or "-" for stdin- Returns:
ObjectInputStream
to be used- Throws:
IOException
- re-thrown
-
lineIteratorFromLocation
public static CloseableLineIterator lineIteratorFromLocation(String location, boolean autoGzip) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.Create anIterator
that can be closed from a not nullable location.Note that the returned instance must be closed by calling
AutoCloseable.close()
.- Parameters:
location
- File name or "-" for stdinautoGzip
- Wrap returned stream throughautoGzip(java.io.InputStream)
.- Returns:
Iterator
for the given location- Throws:
IOException
- re-thrown
-
lineIteratorFromLocation
Deprecated, for removal: This API element is subject to removal in a future version.Create anIterator
that can be closed from a not nullable location.Note that the returned instance must be closed by calling
AutoCloseable.close()
.- Parameters:
location
- File name or "-" for stdin- Returns:
Iterator
for the given location- Throws:
IOException
- re-thrown
-
inputStreamFromNullableLocation
public static Optional<InputStream> inputStreamFromNullableLocation(String location, boolean autoGzip) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.Create in input stream from nullable location.The returned
InputStream
should be closed in a properfinally
block by invoking itsInputStream.close()
method. If stdin used then aCloseShieldInputStream
is returned which is safe to close.- Parameters:
location
- File name or "-" for stdinautoGzip
- Wrap returned stream throughautoGzip(java.io.InputStream)
.- Returns:
- Input stream representing given location
- Throws:
IOException
- thrown byFileInputStream(java.lang.String)
or byautoGzip(java.io.InputStream)
.
-
inputStreamFromNullableLocation
public static Optional<InputStream> inputStreamFromNullableLocation(String location) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.Create in input stream from nullable location.The returned
InputStream
should be closed in a properfinally
block by invoking itsInputStream.close()
method. If stdin used then aCloseShieldInputStream
is returned which is safe to close.- Parameters:
location
- File name or "-" for stdin- Returns:
- Input stream representing given location
- Throws:
IOException
- thrown byFileInputStream(java.lang.String)
or byautoGzip(java.io.InputStream)
.
-
objectInputStreamFromNullableLocation
public static Optional<ObjectInputStream> objectInputStreamFromNullableLocation(String location) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.Create in object input stream from nullable location.The returned
Object
should be closed in a properfinally
block by invoking itsObjectInputStream.close()
method. If stdin used then aCloseShieldInputStream
is used which is safe to close.- Parameters:
location
- File name or "-" for stdin- Returns:
- ObjectInputStream representing given location
- Throws:
IOException
- re-thrown
-
outputStreamFromLocation
Deprecated, for removal: This API element is subject to removal in a future version.OutputStream from a location.- Parameters:
location
- File name or "-" for stdout, "-2" for stderr. Location "/dev/null" is considered as aOutputStream.nullOutputStream()
.- Returns:
- OutputStream for given location which is safe and should be closed explicitly
- Throws:
FileNotFoundException
- thrown byFileOutputStream(java.lang.String)
-
printStreamFromLocation
Deprecated, for removal: This API element is subject to removal in a future version.PrintStream from a location.- Parameters:
location
- File name or "-" for stdout, "-2" for stderr. Location "/dev/null" is considered as aOutputStream.nullOutputStream()
.- Returns:
- UTF-8 encoded PrintStream for given location which is safe and should be closed explicitly
- Throws:
FileNotFoundException
- thrown byFileOutputStream(java.lang.String)
-
objectOutputStreamFromLocation
Deprecated, for removal: This API element is subject to removal in a future version.ObjectOutputStream from a location.- Parameters:
location
- File name or "-" for stdout, "-2" for stderr. Location "/dev/null" is considered as aOutputStream.nullOutputStream()
.- Returns:
- ObjectOutputStream for given location which is safe and should be closed explicitly
- Throws:
IOException
- thrown by underlying streams
-
stringFromLocation
public static String stringFromLocation(String location, boolean autoGzip) throws IllegalArgumentException Deprecated, for removal: This API element is subject to removal in a future version.Read the contents of a location into a String.- Parameters:
location
- Location passed toinputStreamFromLocation(java.lang.String)
autoGzip
- Wrap returned stream throughautoGzip(java.io.InputStream)
.- Returns:
- Contents read by
IOUtils#toString(java.io.InputStream, java.lang.String)
- Throws:
IllegalArgumentException
- When something goes wrong
-
stringFromLocation
Deprecated, for removal: This API element is subject to removal in a future version.Read the contents of a location into a String.- Parameters:
location
- Location passed toinputStreamFromLocation(java.lang.String)
- Returns:
- Contents read by
IOUtils#toString(java.io.InputStream, java.lang.String)
- Throws:
IllegalArgumentException
- When something goes wrong
-
printStreamFromNullableLocation
public static Optional<PrintStream> printStreamFromNullableLocation(String location) throws FileNotFoundException Deprecated, for removal: This API element is subject to removal in a future version.PrintStream from a nullable location.- Parameters:
location
- File name or "-" for stdout, "-2" for stderr- Returns:
- UTF-8 encoded PrintStream for given location which is safe and should be closed explicitly when not null given
- Throws:
FileNotFoundException
- thrown byFileOutputStream(java.lang.String)
-
objectOutputStreamFromNullableLocation
public static Optional<ObjectOutputStream> objectOutputStreamFromNullableLocation(String location) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.ObjectOutputStream from a nullable location.- Parameters:
location
- File name or "-" for stdout, "-2" for stderr- Returns:
- ObjectOutputStream for given location which is safe and should be closed explicitly when not null given
- Throws:
IOException
- re-thrown
-
stringFromNullableLocation
Deprecated, for removal: This API element is subject to removal in a future version.Read the contents of a location when it is not null.- Parameters:
location
- A location or nullautoGzip
- Wrap returned stream throughautoGzip(java.io.InputStream)
.- Returns:
- Contents
-
stringFromNullableLocation
Deprecated, for removal: This API element is subject to removal in a future version.Read the contents of a location when it is not null.- Parameters:
location
- A location or null- Returns:
- Contents
-