java.lang.Object
java.io.OutputStream
java.io.FileOutputStream
net.i2p.util.SecureFileOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
Same as FileOutputStream but sets the file mode so it can only be read and written by the owner only (i.e. 600 on POSIX). Best effort: on filesystems without POSIX permission support, such as Windows, only the read-only attribute can be affected.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final booleanTrue on Java 6, where the file-open options differConstructor Summary
ConstructorsConstructorDescriptionSecureFileOutputStream(File file) Tries to set output file to mode 600.SecureFileOutputStream(File file, boolean append) Tries to set output file to mode 600 whether append = true or false.SecureFileOutputStream(String file) Tries to set output file to mode 600.SecureFileOutputStream(String file, boolean append) Tries to set output file to mode 600 whether append = true or false.Method Summary
Public MethodsModifier and TypeMethodDescription(package private) static booleanWhether it is worth trying to tighten the mode of a file this class opens.static voidTries to set the permissions to 660 (owner+group rw), ignores errors, including on filesystems without POSIX permission support (e.g.static voidTries to set the permissions to 600, ignores errors.Methods inherited from class FileOutputStream
close, getChannel, getFD, write, write, writeMethods inherited from class OutputStream
flush, nullOutputStream
Field Details
oneDotSix
private static final boolean oneDotSixTrue on Java 6, where the file-open options differ
Constructor Details
SecureFileOutputStream
Tries to set output file to mode 600.- Parameters:
file- the path to open for writing, truncating any existing file- Throws:
FileNotFoundException- if the file cannot be opened for writing
SecureFileOutputStream
Tries to set output file to mode 600 whether append = true or false.- Parameters:
file- the path to open for writingappend- true to write at the end of an existing file, false to truncate- Throws:
FileNotFoundException- if the file cannot be opened for writing
SecureFileOutputStream
Tries to set output file to mode 600.- Parameters:
file- the file to open for writing, truncating any existing content- Throws:
FileNotFoundException- if the file cannot be opened for writing
SecureFileOutputStream
Tries to set output file to mode 600 whether append = true or false.- Parameters:
file- the file to open for writingappend- true to write at the end of an existing file, false to truncate- Throws:
FileNotFoundException- if the file cannot be opened for writing
Method Details
canSetPerms
static boolean canSetPerms()Whether it is worth trying to tighten the mode of a file this class opens. False on a pre-1.6 JVM, and false when the router is configured withi2p.insecureFiles, since the setting is then left alone.- Returns:
- true if the permissions should be set, false to skip
setPerms
Tries to set the permissions to 600, ignores errors.- Parameters:
f- the file to make readable and writable by the owner only
setGroupPerms
Tries to set the permissions to 660 (owner+group rw), ignores errors, including on filesystems without POSIX permission support (e.g. Windows). Uses the PosixFilePermission API.- Parameters:
f- the file to make readable and writable by owner and group