Package org.apache.wicket.util.file
Class File
- java.lang.Object
-
- java.io.File
-
- org.apache.wicket.util.file.File
-
- All Implemented Interfaces:
Serializable
,Comparable<File>
,IModifiable
- Direct Known Subclasses:
Folder
public class File extends File implements IModifiable
Simple extension of File that adds an implementation of IModifiable for files. This allows the ModificationWatcher class to watch files for modification. The IModifiable.lastModifiedTime() method also returns a Time object with a more convenient API than either Date or a value in milliseconds.- Author:
- Jonathan Locke
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description File
file(String name)
String
getExtension()
Folder
getParentFolder()
InputStream
inputStream()
Instant
lastModifiedTime()
Returns a Time object representing the most recent time this file was modified.OutputStream
outputStream()
Creates a buffered output stream that writes to this file.Object
readObject()
String
readString()
boolean
remove()
void
sync()
Force contents of file to physical storageString
toQuotedString()
int
write(InputStream input)
Writes the given input stream to this filevoid
write(String string)
Write the given string to this fileint
write(File file)
Writes the given file to this onevoid
writeObject(Serializable object)
-
Methods inherited from class java.io.File
canExecute, canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getFreeSpace, getName, getParent, getParentFile, getPath, getTotalSpace, getUsableSpace, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setExecutable, setExecutable, setLastModified, setReadable, setReadable, setReadOnly, setWritable, setWritable, toPath, toString, toURI, toURL
-
-
-
-
Method Detail
-
file
public File file(String name)
- Parameters:
name
- Name of child file- Returns:
- Child file object
-
getExtension
public String getExtension()
- Returns:
- File extension (whatever is after the last '.' in the file name)
-
getParentFolder
public Folder getParentFolder()
- Returns:
- Parent folder
-
inputStream
public InputStream inputStream() throws FileNotFoundException
- Returns:
- Input stream that reads this file
- Throws:
FileNotFoundException
- Thrown if the file cannot be found
-
lastModifiedTime
public Instant lastModifiedTime()
Returns a Time object representing the most recent time this file was modified.- Specified by:
lastModifiedTime
in interfaceIModifiable
- Returns:
- This file's lastModified() value as a Time object or
null
if that information is not available
-
outputStream
public OutputStream outputStream() throws FileNotFoundException
Creates a buffered output stream that writes to this file. If the parent folder does not yet exist, creates all necessary folders in the path.- Returns:
- Output stream that writes to this file
- Throws:
FileNotFoundException
- Thrown if the file cannot be found
-
readString
public String readString() throws IOException
- Returns:
- String read from this file
- Throws:
IOException
-
readObject
public Object readObject() throws IOException, ClassNotFoundException
- Returns:
- Object read from serialization file
- Throws:
IOException
ClassNotFoundException
-
writeObject
public void writeObject(Serializable object) throws IOException
- Parameters:
object
- Object to write to this file- Throws:
IOException
-
remove
public boolean remove()
- Returns:
- True if the file was removed
- See Also:
File.delete()
-
sync
public void sync() throws IOException
Force contents of file to physical storage- Throws:
IOException
-
toQuotedString
public String toQuotedString()
- Returns:
- This file in double quotes (useful for passing to commands and tools that have issues with spaces in filenames)
-
write
public int write(File file) throws IOException
Writes the given file to this one- Parameters:
file
- The file to copy- Returns:
- number of bytes written
- Throws:
IOException
-
write
public int write(InputStream input) throws IOException
Writes the given input stream to this file- Parameters:
input
- The input- Returns:
- Number of bytes written
- Throws:
IOException
-
write
public void write(String string) throws IOException
Write the given string to this file- Parameters:
string
- The string to write- Throws:
IOException
-
-