|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectlp.wrap.WrapperUtils
public class WrapperUtils
This class provides some static methods that can be useful when handling external commands that receive data on their standard input. It provides:
getCommandName(String) and getShortCommandName(String)),
InputStream to an
OutputStream (transfer(InputStream, OutputStream)) or to a
StringBuilder (transfer(InputStream, StringBuilder))
| Field Summary | |
|---|---|
private byte[] |
byteBuffer
A byte buffer for the transfer(InputStream, OutputStream)
method. |
private char[] |
charBuffer
A character buffer for the transfer(InputStream, StringBuilder)
method. |
private static WrapperUtils |
instance
Reference to the singleton instance of this class. |
| Constructor Summary | |
|---|---|
private |
WrapperUtils()
A private constructor to ensure this is really a singleton. |
| Method Summary | |
|---|---|
String |
dumpToString(InputStream from)
Returns the contents of an InputStream as a string. |
Process |
exec(String command)
Executes the command command through Runtime.exec(String)
and puts the contents of input on the process's standard input. |
String |
getCommandName(String command)
Returns the command's name given the command string, i.e. the part of the command string that precedes the first whitespace character. |
static WrapperUtils |
getInstance()
Returns the singleton instance. |
String |
getShortCommandName(String command)
Returns the command's name without the preceding path given the command string, i.e. the part of the command's name (as defined in getCommandName(String)) that follows the last
File.separatorChar character. |
void |
transfer(InputStream from,
OutputStream to)
Transfers the contents of from to to. |
StringBuilder |
transfer(InputStream from,
StringBuilder to)
Transfers the contents of from to to using the default
character encoding. |
void |
transfer(String from,
OutputStream to)
Transfers the contents of from to to using the default
character encoding. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private final byte[] byteBuffer
transfer(InputStream, OutputStream)
method.
private final char[] charBuffer
transfer(InputStream, StringBuilder)
method.
private static WrapperUtils instance
| Constructor Detail |
|---|
private WrapperUtils()
| Method Detail |
|---|
public static WrapperUtils getInstance()
public String getCommandName(String command)
command
is "/usr/bin/mkdir tmp", then the result will be "/usr/bin/mkdir".
If command is null, then null is returned.
command - the command string
public String getShortCommandName(String command)
getCommandName(String)) that follows the last
File.separatorChar character.
For example, if the separator character is '/' and the command
is "/usr/bin/mkdir tmp", then the result will be "mkdir".
If command is null, then null is returned.
command - the command string
IllegalArgumentException - if command is null.getCommandName(String)
public void transfer(InputStream from,
OutputStream to)
from to to. Invokes
from.close() after the transfer. This method is thread-safe.
from - source of the transferto - destination of the transfer
NullPointerException - if from contains some bytes and
to is null (in other cases the null values don't matter)
IOException - (wrapped in an ExceptionAdapter)
if an I/O error occurs during the transfer
public void transfer(String from,
OutputStream to)
from to to using the default
character encoding. This method is thread-safe. If from is
null, nothing is appended.
from - string convert to bytes and append to toto - destination of the transfer
NullPointerException - if from contains some bytes and
to is null (otherwise the null values are gracefully
ignored)
IOException - (wrapped in an ExceptionAdapter) if
an I/O error occurs during the transfer
public StringBuilder transfer(InputStream from,
StringBuilder to)
from to to using the default
character encoding. Invokes from.close() after the transfer. This
method is thread-safe.
from - source of the transferto - destination of the transfer
NullPointerException - if from contains some bytes and
to is null (otherwise the null values are gracefully
ignored)
IOException - (wrapped in an ExceptionAdapter) if
an I/O error occurs during the transferpublic String dumpToString(InputStream from)
InputStream as a string. Uses the
default encoding to convert bytes to characters. If from is
null, an empty string is returned. This method is thread-safe.
from - the source input stream
from
IOException - (wrapped in an ExceptionAdapter) if
an I/O error occurs during the conversion
public Process exec(String command)
throws WrapperException
command through Runtime.exec(String)
and puts the contents of input on the process's standard input.
The created Process instance is returned.
command - the command to be executed
Process object
NullPointerException - if command is null
IllegalArgumentException - if command is an empty string
WrapperException - if an IOException occurs while creating
the process
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||