/** * Produce a Java IO mode string from the flags in this object. * * @return A Java string suitable for opening files with RandomAccessFile */ public String toJavaModeString() { // Do not open as 'rw' by default since a file with read-only permissions will fail on 'rw' if (isWritable() || isCreate() || isTruncate()) { // Java requires "w" for creating a file that does not exist return "rw"; } else { return "r"; } }
/** * Produce a Java IO mode string from the flags in this object. * * @return A Java string suitable for opening files with RandomAccessFile */ public String toJavaModeString() { // Do not open as 'rw' by default since a file with read-only permissions will fail on 'rw' if (isWritable() || isCreate() || isTruncate()) { // Java requires "w" for creating a file that does not exist return "rw"; } else { return "r"; } }
/** * Produce a Java IO mode string from the flags in this object. * * @return A Java string suitable for opening files with RandomAccessFile */ public String toJavaModeString() { // Do not open as 'rw' by default since a file with read-only permissions will fail on 'rw' if (isWritable() || isCreate() || isTruncate()) { // Java requires "w" for creating a file that does not exist return "rw"; } else { return "r"; } }
/** * Produce a Java IO mode string from the flags in this object. * * @return A Java string suitable for opening files with RandomAccessFile */ public String toJavaModeString() { // Do not open as 'rw' by default since a file with read-only permissions will fail on 'rw' if (isWritable() || isCreate() || isTruncate()) { // Java requires "w" for creating a file that does not exist return "rw"; } else { return "r"; } }
@Override public String toString() { StringBuilder buf = new StringBuilder("ModeFlags(" + flags + "): "); if (isAppendable()) buf.append("APPENDABLE "); if (isBinary()) buf.append("BINARY "); if (isCreate()) buf.append("CREATE "); if (isExclusive()) buf.append("EXCLUSIVE "); if (isReadOnly()) buf.append("READONLY "); if (isText()) buf.append("TEXT "); if (isTruncate()) buf.append("TRUNCATE "); if (isWritable()) { if (isReadable()) { buf.append("RDWR"); } else { buf.append("WRITABLE "); } } return buf.toString(); }
@Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append("ModeFlags(").append(flags).append("): "); if (isAppendable()) buf.append("APPENDABLE "); if (isBinary()) buf.append("BINARY "); if (isCreate()) buf.append("CREATE "); if (isExclusive()) buf.append("EXCLUSIVE "); if (isReadOnly()) buf.append("READONLY "); if (isText()) buf.append("TEXT "); if (isTemporary()) buf.append("TMPFILE "); if (isTruncate()) buf.append("TRUNCATE "); if (isWritable()) { if (isReadable()) { buf.append("RDWR"); } else { buf.append("WRITABLE "); } } return buf.toString(); }
@Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append("ModeFlags(").append(flags).append("): "); if (isAppendable()) buf.append("APPENDABLE "); if (isBinary()) buf.append("BINARY "); if (isCreate()) buf.append("CREATE "); if (isExclusive()) buf.append("EXCLUSIVE "); if (isReadOnly()) buf.append("READONLY "); if (isText()) buf.append("TEXT "); if (isTemporary()) buf.append("TMPFILE "); if (isTruncate()) buf.append("TRUNCATE "); if (isWritable()) { if (isReadable()) { buf.append("RDWR"); } else { buf.append("WRITABLE "); } } return buf.toString(); }
@Override public String toString() { StringBuilder buf = new StringBuilder("ModeFlags(" + flags + "): "); if (isAppendable()) buf.append("APPENDABLE "); if (isBinary()) buf.append("BINARY "); if (isCreate()) buf.append("CREATE "); if (isExclusive()) buf.append("EXCLUSIVE "); if (isReadOnly()) buf.append("READONLY "); if (isText()) buf.append("TEXT "); if (isTruncate()) buf.append("TRUNCATE "); if (isWritable()) { if (isReadable()) { buf.append("RDWR"); } else { buf.append("WRITABLE "); } } return buf.toString(); }
private Channel createChannel(ModeFlags flags) throws IOException { SeekableByteChannel fileChannel; try{ if (flags.isWritable() && !flags.isReadable()) { FileOutputStream fos = new FileOutputStream(file, flags.isAppendable()); fileChannel = fos.getChannel(); } else { RandomAccessFile raf = new RandomAccessFile(file, flags.toJavaModeString()); fileChannel = raf.getChannel(); // O_APPEND specifies that all writes will always be at the end of the open file // (even if we happened to have seek'd away from the end of the file o_O). RAF // does not have these semantics so we wrap it to support this unusual case. if (flags.isAppendable()) fileChannel = new AppendModeChannel((FileChannel) fileChannel); } } catch (FileNotFoundException ex) { throw mapFileNotFoundOnGetChannel(this, ex); } try { if (flags.isTruncate()) fileChannel.truncate(0); } catch (IOException ioe) { // ignore; it's a pipe or fifo that can't be truncated (we only care about illegal seek). if (!"Illegal seek".equals(ioe.getMessage())) throw ioe; } return fileChannel; }
private Channel createChannel(ModeFlags flags) throws IOException { SeekableByteChannel fileChannel; try{ if (flags.isWritable() && !flags.isReadable()) { FileOutputStream fos = new FileOutputStream(file, flags.isAppendable()); fileChannel = fos.getChannel(); } else { RandomAccessFile raf = new RandomAccessFile(file, flags.toJavaModeString()); fileChannel = raf.getChannel(); // O_APPEND specifies that all writes will always be at the end of the open file // (even if we happened to have seek'd away from the end of the file o_O). RAF // does not have these semantics so we wrap it to support this unusual case. if (flags.isAppendable()) fileChannel = new AppendModeChannel((FileChannel) fileChannel); } } catch (FileNotFoundException ex) { throw mapFileNotFoundOnGetChannel(this, ex); } try { if (flags.isTruncate()) fileChannel.truncate(0); } catch (IOException ioe) { // ignore; it's a pipe or fifo that can't be truncated (we only care about illegal seek). if (!"Illegal seek".equals(ioe.getMessage())) throw ioe; } return fileChannel; }
if (flags.isTruncate()) fileChannel.truncate(0); } catch (IOException ioe) { if (ioe.getMessage().equals("Illegal seek")) {
if (flags.isTruncate()) fileChannel.truncate(0); } catch (IOException ioe) { if (ioe.getMessage().equals("Illegal seek")) {
if (modes.isTruncate()) file.setLength(0L);
if (modes.isTruncate()) file.setLength(0L);
if (modes.isTruncate()) file.setLength(0L);
if (modes.isTruncate()) file.setLength(0L);
if (ptr.modes.isTruncate()) { ptr.string.modifyCheck(); ptr.string.empty();
if (ptr.modes.isTruncate()) { ptr.string.modifyCheck(); ptr.string.empty();