private Channel createChannel(ModeFlags flags) throws IOException { FileChannel fileChannel; /* Because RandomAccessFile does not provide a way to pass append * mode, we must manually seek if using RAF. FileOutputStream, * however, does properly honor append mode at the lowest levels, * reducing append write costs when we're only doing writes. * * The code here will use a FileOutputStream if we're only writing, * setting isInAppendMode to true to disable our manual seeking. * * RandomAccessFile does not handle append for us, so if we must * also be readable we pass false for isInAppendMode to indicate * we need manual seeking. */ 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(); } } catch (FileNotFoundException ex) { throw mapFileNotFoundOnGetChannel(this, ex); } return fileChannel; }
private Channel createChannel(ModeFlags flags) throws IOException { FileChannel fileChannel; /* Because RandomAccessFile does not provide a way to pass append * mode, we must manually seek if using RAF. FileOutputStream, * however, does properly honor append mode at the lowest levels, * reducing append write costs when we're only doing writes. * * The code here will use a FileOutputStream if we're only writing, * setting isInAppendMode to true to disable our manual seeking. * * RandomAccessFile does not handle append for us, so if we must * also be readable we pass false for isInAppendMode to indicate * we need manual seeking. */ 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(); } } catch (FileNotFoundException ex) { throw mapFileNotFoundOnGetChannel(this, ex); } 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; }
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; }