Class Files
- java.lang.Object
-
- org.zkoss.io.Files
-
public class Files extends java.lang.ObjectFile related utilities.- Author:
- tomyeh
-
-
Field Summary
Fields Modifier and Type Field Description static intCP_OVERWRITEOverwrites the destination file.static intCP_PRESERVEPreserves the last modified time and other attributes if possible.static intCP_SKIP_SVNSkips the SVN related files.static intCP_UPDATECopy only when the source is newer or when the destination is missing.static charDRIVE_SEPARATOR_CHARThe separator representing the drive in a path.
-
Constructor Summary
Constructors Modifier Constructor Description protectedFiles()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclose(java.io.InputStream strm)Close an input stream without throwing an exception.static voidclose(java.io.OutputStream strm)Close an output stream without throwing an exception.static voidclose(java.io.Reader reader)Close a reader without throwing an exception.static voidclose(java.io.Writer writer)Close a writer without throwing an exception.static voidcopy(java.io.File dst, java.io.File src, int flags)Copies a file or a directory into another.static voidcopy(java.io.File dst, java.io.InputStream in)Copies an input stream into a file (the original content, if any, are erased).static voidcopy(java.io.File dst, java.io.Reader reader, java.lang.String charset)Copies a reader into a file (the original content, if any, are erased).static voidcopy(java.io.OutputStream out, java.io.InputStream in)Copies an input stream to a output stream.static voidcopy(java.io.Writer writer, java.io.Reader reader)Copies a reader into a writer.static java.lang.StringcorrectSeparator(java.lang.String flnm)Corrects the separator from '/' to the system dependent one.static booleandeleteAll(java.io.File file)Deletes all files under the specified path.static java.lang.Stringlocate(java.lang.String flnm)Locates a file based o the current Locale.static java.lang.Stringnormalize(java.lang.String path)Normalizes the specified path.static java.lang.Stringnormalize(java.lang.String parentPath, java.lang.String childPath)Normalizes the concatenation of two paths.static byte[]readAll(java.io.InputStream in)Returns all bytes in the input stream, never null (but its length might zero).static java.lang.StringBufferreadAll(java.io.Reader reader)Returns all characters in the reader, never null (but its length might zero).static voidwrite(java.io.Writer out, java.lang.StringBuffer sb)Writes the specified string buffer to the specified writer.
-
-
-
Field Detail
-
DRIVE_SEPARATOR_CHAR
public static final char DRIVE_SEPARATOR_CHAR
The separator representing the drive in a path. In Windows, it is ':', while 0 in other platforms.
-
CP_PRESERVE
public static int CP_PRESERVE
Preserves the last modified time and other attributes if possible.- See Also:
copy(File, File, int)
-
CP_UPDATE
public static int CP_UPDATE
Copy only when the source is newer or when the destination is missing.- See Also:
copy(File, File, int)
-
CP_OVERWRITE
public static int CP_OVERWRITE
Overwrites the destination file.- See Also:
copy(File, File, int)
-
CP_SKIP_SVN
public static int CP_SKIP_SVN
Skips the SVN related files.- Since:
- 5.0.0
-
-
Method Detail
-
correctSeparator
public static final java.lang.String correctSeparator(java.lang.String flnm)
Corrects the separator from '/' to the system dependent one. Note: always uses '/' even though Windows uses '\\'.
-
readAll
public static final byte[] readAll(java.io.InputStream in) throws java.io.IOExceptionReturns all bytes in the input stream, never null (but its length might zero).Notice: this method is memory hungry.
Notice: it doesn't close
in- Throws:
java.io.IOException
-
readAll
public static final java.lang.StringBuffer readAll(java.io.Reader reader) throws java.io.IOExceptionReturns all characters in the reader, never null (but its length might zero).Notice: this method is memory hungry.
- Throws:
java.io.IOException
-
copy
public static final void copy(java.io.Writer writer, java.io.Reader reader) throws java.io.IOExceptionCopies a reader into a writer.Notice: it doesn't close
readerorwriter- Parameters:
writer- the destinationreader- the source- Throws:
java.io.IOException
-
copy
public static final void copy(java.io.OutputStream out, java.io.InputStream in) throws java.io.IOExceptionCopies an input stream to a output stream.Notice: it doesn't close
inorout- Parameters:
out- the destinationin- the source- Throws:
java.io.IOException
-
copy
public static final void copy(java.io.File dst, java.io.Reader reader, java.lang.String charset) throws java.io.IOExceptionCopies a reader into a file (the original content, if any, are erased). The source and destination files will be closed after copied.- Parameters:
dst- the destinationreader- the sourcecharset- the charset; null as default (ISO-8859-1).- Throws:
java.io.IOException
-
copy
public static final void copy(java.io.File dst, java.io.InputStream in) throws java.io.IOExceptionCopies an input stream into a file (the original content, if any, are erased). The file will be closed after copied.- Parameters:
dst- the destinationin- the source- Throws:
java.io.IOException
-
copy
public static final void copy(java.io.File dst, java.io.File src, int flags) throws java.io.IOExceptionCopies a file or a directory into another.If neither
CP_UPDATEnorCP_OVERWRITE, IOException is thrown if the destination exists.- Parameters:
flags- any combination ofCP_UPDATE,CP_PRESERVE,CP_OVERWRITE.- Throws:
java.io.IOException
-
deleteAll
public static final boolean deleteAll(java.io.File file)
Deletes all files under the specified path.
-
close
public static final void close(java.io.InputStream strm)
Close an input stream without throwing an exception.
-
close
public static final void close(java.io.Reader reader)
Close a reader without throwing an exception.
-
close
public static final void close(java.io.OutputStream strm)
Close an output stream without throwing an exception.- Since:
- 5.0.4
-
close
public static final void close(java.io.Writer writer)
Close a writer without throwing an exception.- Since:
- 5.0.4
-
normalize
public static final java.lang.String normalize(java.lang.String parentPath, java.lang.String childPath)Normalizes the concatenation of two paths.- Parameters:
parentPath- the parent's pathchildPath- the child's path If it starts with "/", parentPath is ignored.- Since:
- 5.0.0
-
normalize
public static final java.lang.String normalize(java.lang.String path)
Normalizes the specified path. It removes consecutive slashes, ending slashes, redundant . and ...Unlike
File,normalize(java.lang.String, java.lang.String)always assumes the separator to be '/', and it cannot handle the device prefix (e.g., c:). However, it handles //.- Parameters:
path- the path to normalize. If null, an empty string is returned.- Since:
- 5.0.0
-
write
public static final void write(java.io.Writer out, java.lang.StringBuffer sb) throws java.io.IOExceptionWrites the specified string buffer to the specified writer. Use this method instead of out.write(sb.toString()), if sb.length() is large.- Throws:
java.io.IOException- Since:
- 5.0.0
-
locate
public static final java.lang.String locate(java.lang.String flnm)
Locates a file based o the current Locale. It never returns null.If the filename contains "*", it will be replaced with a proper Locale. For example, if the current Locale is zh_TW and the resource is named "ab*.cd", then it searches "ab_zh_TW.cd", "ab_zh.cd" and then "ab.cd", until any of them is found.
Note: "*" must be right before ".", or the last character. For example, "ab*.cd" and "ab*" are both correct, while "ab*cd" and "ab*\/cd" are ignored.
Unlike
Locators.locate(java.lang.String, java.util.Locale, org.zkoss.util.resource.Locator), the filename must contain '*', whileLocators.locate(java.lang.String, java.util.Locale, org.zkoss.util.resource.Locator)always tries to locate the file by inserting the locale before '.'. In other words, Files.locate("/a/b*.c") is similar to Locators.locate(("/a/b.c", null, a_file_locator);- Parameters:
flnm- the filename to locate. If it doesn't contain any '*', it is returned directly. If the file is not found, flnm is returned, too.- Since:
- 5.0.0
- See Also:
Locales.getCurrent()
-
-