| java.lang.Object com.nabhinc.util.IOUtil
IOUtil | public class IOUtil (Code) | | Provides utility methods for reading / writing from files / URLs
author: Padmanabh Dabke author: (c) 2001 Nabh Information Systems, Inc. All Rights Reserved. |
Method Summary | |
public static void | convertToUTF(Properties props, String fromCharset) Utility method to convert values in specified properties object to UTF-8.
Parameters: props - The Properties object which values to be converted. Parameters: fromCharset - Characters encoding. | public static void | copyDirectory(File srcDir, File destDir) | public static void | copyFile(File srcFile, File destFile, boolean overwrite) | public static void | copyFile(File srcFile, File destFile) | public static void | createFile(String filePath, String newContent, String charset) Create a new file with content and file path specified. | public static boolean | deleteDirectory(File dir) | public static void | deleteFile(String filename) Delete a file. | public static Serializable | deserializeObject(byte[] ser) Reads a Java object from the byte array. | public static Serializable | destringifyObject(String str) Deserializes an object from a string. | public static byte[] | getBytes(InputStream inputStream) | public static byte[] | getFileContentAsBytes(File file) | public static String | getFileContentAsString(File file, String charset) Reads contents of a file as a string and encodes based on character encoding
specified. | public static String | getFileContentAsString(File file) Reads contents of a file as a UTF-8 encoded string. | public static String | getInputStreamContentAsString(InputStream is, String charset) | public static String | getInputStreamContentAsString(InputStream is) Reads contents of an input stream as a UTF-8 encoded string. | public static String | getURLContentAsString(String urlStr) Reads contents of a URL as a string. | public static void | loadSystemPropertiesFromFile(String file) Reads properties from a file and merges them with the System properties. | public static void | loadSystemPropertiesFromURL(String urlStr) Reads properties from a URL and merges them with the System properties. | public static void | mergeWithSystemProperties(java.util.Properties props) Merges given properties with system properties. | public static void | saveAndBackupFile(File file, String newContent) Create a backup (old content) of a file (with extension .bak) and update the content
of the specified file based on UTF-8 charset encoding. | public static void | saveAndBackupFile(File file, String newContent, String charset) Create a backup (old content) of a file (with extension .bak) and update the content
of the specified file. | public static void | saveInputStreamContentToFile(InputStream is, String filePath) | public static byte[] | serializeObject(Serializable obj) | public static String | stringifyObject(Serializable obj) |
convertToUTF | public static void convertToUTF(Properties props, String fromCharset) throws IOException(Code) | | Utility method to convert values in specified properties object to UTF-8.
Parameters: props - The Properties object which values to be converted. Parameters: fromCharset - Characters encoding. The charset's name must be one of name supported java.nio.charset.Charset charset throws: IOException - |
createFile | public static void createFile(String filePath, String newContent, String charset) throws IOException(Code) | | Create a new file with content and file path specified. It will attempt to
overwrite the existing one if the file is writeable.
Parameters: filePath - The file path Parameters: newContent - The file content Parameters: charset - Characters encoding. The charset's name must be one of name supported java.nio.charset.Charset charset throws: IOException - Thrown if the file path is not specified or trying to overwrite read only file. |
deleteDirectory | public static boolean deleteDirectory(File dir)(Code) | | |
deleteFile | public static void deleteFile(String filename) throws IOException(Code) | | Delete a file.
Parameters: filename - File to be deleted. throws: IOException - If the file is not exist, or a directory, or not able to be deleted. |
getFileContentAsString | public static String getFileContentAsString(File file, String charset) throws java.io.IOException(Code) | | Reads contents of a file as a string and encodes based on character encoding
specified. Default character encoding is UTF-8.
String holding the file contents Parameters: file - File to be read Parameters: charset - Characters encoding. The charset's name must be one of name supported java.nio.charset.Charset charset exception: java.io.IOException - |
loadSystemPropertiesFromFile | public static void loadSystemPropertiesFromFile(String file) throws java.io.IOException(Code) | | Reads properties from a file and merges them with the System properties.
Parameters: file - Property file path. exception: java.io.IOException - The property file could notbe found. |
mergeWithSystemProperties | public static void mergeWithSystemProperties(java.util.Properties props)(Code) | | Merges given properties with system properties.
|
saveAndBackupFile | public static void saveAndBackupFile(File file, String newContent) throws IOException(Code) | | Create a backup (old content) of a file (with extension .bak) and update the content
of the specified file based on UTF-8 charset encoding.
Parameters: file - File which content to be updated. Parameters: newContent - New content exception: java.io.IOException - |
saveAndBackupFile | public static void saveAndBackupFile(File file, String newContent, String charset) throws IOException(Code) | | Create a backup (old content) of a file (with extension .bak) and update the content
of the specified file. Default character encoding is UTF-8, if charset is not specified.
If the file does not exist, it will attempt to create one.
Parameters: file - File which content to be updated. Parameters: newContent - New content Parameters: charset - Characters encoding. The charset's name must be one of name supported java.nio.charset.Charset charset exception: java.io.IOException - |
serializeObject | public static byte[] serializeObject(Serializable obj) throws IOException(Code) | | Serializes the given object into a byte array
Parameters: obj - Byte array containing serialized object. throws: IOException - |
stringifyObject | public static String stringifyObject(Serializable obj) throws IOException(Code) | | Creates a Base 64 encoded string representation of a serialized object
Parameters: obj - Object to be serialized String representing the serialized object. throws: IOException - |
|
|