|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.optimizationservices.oscommon.util.IOUtil
public class IOUtil
The IOUtil
class contains methods for performing
common basic input-output (I/O) operations, such as file reading/writing,
used by various components in the
Optimization Services (OS) framework.
Field Summary | |
---|---|
java.lang.String |
m_sName
m_sName holds the name of this class. |
Constructor Summary | |
---|---|
IOUtil()
|
Method Summary | |
---|---|
static boolean |
appendStringToFile(java.lang.String string,
java.lang.String fileName)
Appends a string to a file. |
static java.lang.String |
bytesToEncodedString(byte[] byteArray)
Converts an array of bytes into a base64 encoded string. |
static boolean |
bytesToFile(byte[] byteArray,
java.lang.String fileName)
Save an array of bytes into a file. |
static java.lang.Object |
bytesToObject(byte[] byteArray)
Converts an array of bytes into an object. |
static java.lang.String |
bytesToString(byte[] byteArray)
Converts an array of bytes into a string (unencoded). |
static boolean |
cleanUpDisk()
clean up disks, mainly including deleting temp files. |
static boolean |
copyFile(java.lang.String from,
java.lang.String to)
copy a file. |
static boolean |
createFile(java.lang.String file)
Create a file. |
static java.lang.String |
decodeString(java.lang.String encodedString)
Deconde a base64 encoded string. |
static boolean |
deleteDir(java.lang.String dir)
Delete a directory. |
static boolean |
deleteFile(java.lang.String file)
delete a file. |
static byte[] |
encodedStringToBytes(java.lang.String string)
Decodes a base64 encoded string and return them in an array of bytes. |
static boolean |
encodedStringToFile(java.lang.String string,
java.lang.String fileName)
Decodes and saves a base64 encoded string into a file. |
static java.lang.Object |
encodedStringToObject(java.lang.String string)
Decodes a base64 encoded string and return them in an object. |
static java.lang.String |
encodeString(java.lang.String string)
Encode a plain string with base64 encoding. |
static java.lang.String |
exceptionStackToString(java.lang.Exception e)
Convert printStackTrace() to a String. |
static boolean |
existsFileOrDir(java.lang.String path)
check if a file or directory exists. |
static byte[] |
fileToBytes(java.lang.String fileName)
Retrieve a file into an array of bytes. |
static java.lang.String |
fileToEncodedString(java.lang.String fileName)
Converts any file into a base64 encoded string. |
static java.io.InputStream |
fileToInputStream(java.lang.String fileName)
|
static java.lang.Object |
fileToObject(java.lang.String fileName)
Converts file that was previously serialized from an object into an object in memory. |
static java.io.OutputStream |
fileToOnputStream(java.lang.String fileName)
|
static java.lang.String |
fileToString(java.lang.String fileName)
Read a file into a string (unencoded). |
static java.lang.String |
getCurrentDir()
Get the current directory. |
static double |
getFreeDiskSpace(java.lang.String path)
get free disk space. |
static long |
getLastWriteTime(java.lang.String file)
get the last write time of the file. |
static java.lang.String |
getParentDir()
Get the parent directory. |
static boolean |
isDir(java.lang.String path)
test whether a path is a directory or not. |
static boolean |
log(java.lang.String logMessage,
java.lang.String logFileName)
|
static void |
main(java.lang.String[] args)
main for test purposes. |
static boolean |
makeDir(java.lang.String dir)
Make a directory. |
static boolean |
moveFile(java.lang.String from,
java.lang.String to)
move a file. |
static byte[] |
objectToBytes(java.lang.Object object)
Return an object in an array of bytes. |
static java.lang.String |
objectToEncodedString(java.lang.Object object)
Return an object in a base64 encoded string. |
static boolean |
objectToFile(java.lang.Object object,
java.lang.String fileName)
Save a object into a file. |
static boolean |
print(java.lang.String s)
Print out a string message. |
static boolean |
print(java.lang.String s,
java.io.OutputStream outputStream)
Print out a string message. |
static boolean |
println()
Print out a line feed "\n". |
static boolean |
println(java.lang.String s)
Print out a string message with an extra line feed "\n". |
static byte[] |
readBytesFromURL(java.lang.String url)
Reads from a url to a string in memory. |
static java.lang.String |
readStringFromFile(java.lang.String fileName)
Reads from a file to a string in memory. |
static java.lang.String |
readStringFromURL(java.lang.String url)
Reads from a url to a string in memory. |
static boolean |
stringFileToBinaryFile(java.lang.String inFileName,
java.lang.String outFileName)
Converts a string file to a binary file. |
static byte[] |
stringToBytes(java.lang.String string)
Return a string (unencoded) in an array of bytes. |
static boolean |
stringToFile(java.lang.String string,
java.lang.String fileName)
Saves a string into a file. |
static java.io.InputStream |
stringToInputStream(java.lang.String string)
|
static boolean |
writeStringToFile(java.lang.String string,
java.lang.String fileName)
Writes a string to a file. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public java.lang.String m_sName
Constructor Detail |
---|
public IOUtil()
Method Detail |
---|
public static java.lang.String encodeString(java.lang.String string)
string
- holds the plain string to be encoded.
public static java.lang.String decodeString(java.lang.String encodedString)
string
- holds the base64 encoded string to be decoded into a plain string.
public static java.lang.String fileToString(java.lang.String fileName)
fileName
- holds the name of the file to read.
public static boolean stringToFile(java.lang.String string, java.lang.String fileName)
string
- holds the string to be saved.fileName
- holds the name of the file to save the string.
public static java.lang.String fileToEncodedString(java.lang.String fileName)
fileName
- holds the name of the file to be converted to a base64 encoded string.
public static boolean encodedStringToFile(java.lang.String string, java.lang.String fileName)
string
- holds base64 encoded string to be decoded and saved.fileName
- holds the name of the file to save the string.
public static java.lang.String bytesToString(byte[] byteArray)
byteArray
- holds the array of bytes to be converted to a string.
public static byte[] stringToBytes(java.lang.String string)
string
- holds string to be put in an array of bytes.
public static java.lang.String bytesToEncodedString(byte[] byteArray)
byteArray
- holds the array of bytes to be converted to a base64 encoded string.
public static byte[] encodedStringToBytes(java.lang.String string)
string
- holds base64 encoded string to be decoded and put in an array of bytes.
public static byte[] objectToBytes(java.lang.Object object)
object
- holds the serializable object to be put into an array of bytes.
java.io.Serializable
. The method returns null if an error occurs.public static java.lang.Object bytesToObject(byte[] byteArray)
byteArray
- holds the array of bytes to be converted to an object.
java.io.Serializable
. The method returns null if
an error occurs.public static java.lang.String objectToEncodedString(java.lang.Object object)
object
- holds the serializable object to be encoded to a string.
java.io.Serializable
. The method returns null if an error occurs.public static java.lang.Object encodedStringToObject(java.lang.String string)
string
- holds base64 encoded string to be decoded and converted to an object.
java.io.Serializable
. The method returns null if
an error occurs.public static boolean objectToFile(java.lang.Object object, java.lang.String fileName)
object
- holds the serializable object to be saved into a file.fileName
- holds the name of the file to save the object.
java.io.Serializable
.public static java.lang.Object fileToObject(java.lang.String fileName)
fileName
- holds the name of the file to was previsouly serialized from an object.
java.io.Serializable
. The method returns null if
an error occurs.public static boolean bytesToFile(byte[] byteArray, java.lang.String fileName)
byteArray
- holds an array of bytes to be saved into a file.fileName
- holds the name of the file to save the array of bytes.
public static byte[] fileToBytes(java.lang.String fileName)
fileName
- holds the name of the file to be retrieved into the array of bytes.
public static boolean stringFileToBinaryFile(java.lang.String inFileName, java.lang.String outFileName)
inFileName
- holds the name of the string file.outFileName
- holds the name of the binary file to be converted.
public static java.lang.String readStringFromFile(java.lang.String fileName)
fileName
- holds the file name of the file to be converted into a string
public static boolean writeStringToFile(java.lang.String string, java.lang.String fileName)
string
- holds the string to be written to a file.fileName
- holds the file name of the file to save the string.
public static boolean appendStringToFile(java.lang.String string, java.lang.String fileName)
string
- holds the string to be appended to a file.fileName
- holds the file name of the file to append the string.
public static java.lang.String readStringFromURL(java.lang.String url)
url
- holds the link address of the content to be converted into a string.
public static byte[] readBytesFromURL(java.lang.String url)
url
- holds the link address of the content to be converted into a string.
public static java.io.InputStream stringToInputStream(java.lang.String string)
string
- holds the string to be converted to an inputstream.
public static java.io.InputStream fileToInputStream(java.lang.String fileName)
file
- holds the file to converted to an inputstream.
public static java.io.OutputStream fileToOnputStream(java.lang.String fileName)
file
- holds the file to converted to an Outputstream.
public static boolean log(java.lang.String logMessage, java.lang.String logFileName)
public static boolean print(java.lang.String s, java.io.OutputStream outputStream)
s
- holds the string message to print.outputStream
- holds the output stream to print the message to
public static boolean println()
public static boolean println(java.lang.String s)
s
- holds the string message to print.
public static boolean print(java.lang.String s)
s
- holds the string message to print.
public static java.lang.String exceptionStackToString(java.lang.Exception e)
e
- holds the exception to be redirected.
public static boolean cleanUpDisk()
public static boolean existsFileOrDir(java.lang.String path)
path
- holds the the file or dir path to check.
public static long getLastWriteTime(java.lang.String file)
file
- holds the name of the file to check.
public static boolean isDir(java.lang.String path)
path
- holds the file or dir path.
public static boolean createFile(java.lang.String file)
file
- holds the name of the file to create.
public static boolean deleteFile(java.lang.String file)
file
- holds the name of the file to delete.
public static boolean copyFile(java.lang.String from, java.lang.String to)
from
- holds the file to copy from.to
- holds the file to copy to.
public static boolean moveFile(java.lang.String from, java.lang.String to)
from
- holds the file to move from.to
- holds the file to move to.
public static boolean makeDir(java.lang.String dir)
dir
- holds the directory path
public static boolean deleteDir(java.lang.String dir)
dir
- holds the directory path
public static java.lang.String getCurrentDir()
public static java.lang.String getParentDir()
public static double getFreeDiskSpace(java.lang.String path) throws java.io.IOException
path
- holds the path to get free space for, (including the colon on the windows system.)
java.io.IOException
- if an error occurspublic static void main(java.lang.String[] args)
argv
- command line arguments.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |