@Override public void flush() { if (outputStream == null) { return; } try { outputStream.flush(); } catch (IOException ioe) { throw Py.IOError(ioe); } }
public void close() { try { writer.close(); closed = true; } catch (IOException e) { throw Py.IOError(e); } }
/** * Raise a TypeError indicating the specified operation is not supported. * * @param methodName * the String name of the operation */ protected void unsupported(String methodName) { String qualifiedName = getClass().getName(); String className = qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1); throw Py.IOError(String.format("%s.%s() not supported", className, methodName)); } }
/** * Raise an IOError if the file is not writable. * */ public void checkWritable() { if (!writable()) { throw Py.IOError(Errno.EBADF); } }
@Override public long tell() { checkClosed(); try { return fileChannel.position(); } catch (IOException ioe) { throw Py.IOError(ioe); } }
private static PyObject newFile(File file) { try { return new PyFile(new FileInputStream(file)); } catch (IOException ioe) { throw Py.IOError(ioe); } }
/** * Raise an IOError if the file is not readable. * */ public void checkReadable() { if (!readable()) { throw Py.IOError(Errno.EBADF); } }
public void close() { try { if (!closed()) { reader.close(); closed = true; } } catch (IOException e) { throw Py.IOError(e); } }
public synchronized void flush() { checkClosed(); try { writer.flush(); } catch (IOException e) { throw Py.IOError(e); } }
@Override public int write(ByteBuffer buf) { checkClosed(); checkWritable(); try { return writeChannel.write(buf); } catch (IOException ioe) { throw Py.IOError(ioe); } }
@Override public int readinto(ByteBuffer buf) { checkClosed(); checkReadable(); try { return socketChannel.read(buf); } catch (IOException ioe) { throw Py.IOError(ioe); } }
@Override public void close() { if (closed()) { return; } try { fileChannel.close(); } catch (IOException ioe) { throw Py.IOError(ioe); } super.close(); }
@Override public int readinto(ByteBuffer buf) { checkClosed(); checkReadable(); try { return readChannel.read(buf); } catch (IOException ioe) { throw Py.IOError(ioe); } }
@Override public int readinto(ByteBuffer buf) { checkClosed(); checkReadable(); try { int n = fileChannel.read(buf); return n > 0 ? n : 0; } catch (IOException ioe) { throw Py.IOError(ioe); } }
private void checkFileWritable() { if (inReadMode) { throw Py.IOError("File in read-only mode"); } if (buffer == null || buffer.closed()) { throw Py.ValueError("Stream closed"); } }
@Override public int readinto(ByteBuffer buf) { checkClosed(); checkReadable(); throw Py.IOError(Errno.ENOTCONN); }
@Override public int write(ByteBuffer buf) { checkClosed(); checkWritable(); throw Py.IOError(Errno.EBADF); } }
@Override public int write(ByteBuffer buf) { checkClosed(); checkWritable(); try { return emulateAppend ? appendFromByteBuffer(buf) // use this helper function to advance the file channel's position post-write : fileChannel.write(buf); // this does change the file channel's position } catch (IOException ioe) { throw Py.IOError(ioe); } }
@Override public int readinto(ByteBuffer buf) { checkClosed(); checkReadable(); try { return socketChannel.read(buf); } catch (IOException ioe) { throw Py.IOError(ioe); } }