/** * closes a reader, and logs exceptions * * @param reader the reader to close */ public static void close(Reader reader) { close((Closeable)reader); }
/** * closes an output stream, and logs exceptions * * @param os the output stream to close */ public static void close(OutputStream os) { close((Closeable)os); }
/** * closes a writer, and logs exceptions * * @param writer the writer to close */ public static void close(Writer writer) { close((Closeable)writer); }
/** * closes an input stream, and logs exceptions * * @param is the input stream to close */ public static void close(InputStream is) { close((Closeable)is); }
/** * closes an input stream, and logs exceptions * * @param is the input stream to close */ public static void close(InputStream is) { close((Closeable)is); }
/** * closes an output stream, and logs exceptions * * @param os the output stream to close */ public static void close(OutputStream os) { close((Closeable)os); }
/** * closes a writer, and logs exceptions * * @param writer the writer to close */ public static void close(Writer writer) { close((Closeable)writer); }
/** * closes a reader, and logs exceptions * * @param reader the reader to close */ public static void close(Reader reader) { close((Closeable)reader); }
public void run() { String line; try { while ((line = reader.readLine()) != (null)) { System.out.println("[" + mode + "] " + line); } } catch (IOException ignore) { /* ignore */ } finally { IO.close(reader); } } }
/** * @param file */ public DirectNIOBuffer(File file) throws IOException { super(READONLY,NON_VOLATILE); FileInputStream fis = null; FileChannel fc = null; try { fis = new FileInputStream(file); fc = fis.getChannel(); _buf = fc.map(FileChannel.MapMode.READ_ONLY, 0, file.length()); setGetIndex(0); setPutIndex((int)file.length()); _access=IMMUTABLE; } finally { if (fc != null) try {fc.close();} catch (IOException e){LOG.ignore(e);} IO.close(fis); } }
/** * @param file */ public DirectNIOBuffer(File file) throws IOException { super(READONLY,NON_VOLATILE); FileInputStream fis = null; FileChannel fc = null; try { fis = new FileInputStream(file); fc = fis.getChannel(); _buf = fc.map(FileChannel.MapMode.READ_ONLY, 0, file.length()); setGetIndex(0); setPutIndex((int)file.length()); _access=IMMUTABLE; } finally { if (fc != null) try {fc.close();} catch (IOException e){LOG.ignore(e);} IO.close(fis); } }
/** * @param file */ public DirectNIOBuffer(File file) throws IOException { super(READONLY,NON_VOLATILE); FileInputStream fis = null; FileChannel fc = null; try { fis = new FileInputStream(file); fc = fis.getChannel(); _buf = fc.map(FileChannel.MapMode.READ_ONLY, 0, file.length()); setGetIndex(0); setPutIndex((int)file.length()); _access=IMMUTABLE; } finally { if (fc != null) try {fc.close();} catch (IOException e){LOG.ignore(e);} IO.close(fis); } }
/** * @param file */ public DirectNIOBuffer(File file) throws IOException { super(READONLY,NON_VOLATILE); FileInputStream fis = null; FileChannel fc = null; try { fis = new FileInputStream(file); fc = fis.getChannel(); _buf = fc.map(FileChannel.MapMode.READ_ONLY, 0, file.length()); setGetIndex(0); setPutIndex((int)file.length()); _access=IMMUTABLE; } finally { if (fc != null) try {fc.close();} catch (IOException e){LOG.ignore(e);} IO.close(fis); } }
@Override public void incomingFrame(Frame frame) { saveFrame(frame,false); try { nextIncomingFrame(frame); } catch (Throwable t) { IO.close(incomingChannel); incomingChannel = null; throw t; } }
@Override public void outgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMode) { saveFrame(frame,true); try { nextOutgoingFrame(frame,callback,batchMode); } catch (Throwable t) { IO.close(outgoingChannel); outgoingChannel = null; throw t; } }
@Override public void onCompleteFailure(Throwable x) { abort(x); _channel.getByteBufferPool().release(_buffer); IO.close(_in); super.onCompleteFailure(x); } }
@Override public void onCompleteFailure(Throwable x) { abort(x); _channel.getByteBufferPool().release(_buffer); IO.close(_in); super.onCompleteFailure(x); } }
public synchronized void deIdle() { if (isIdled()) { // Access now to prevent race with idling period access(System.currentTimeMillis()); if (LOG.isDebugEnabled()) LOG.debug("De-idling " + super.getId()); FileInputStream fis = null; try { File file = new File(_hashSessionManager._storeDir, super.getId()); if (!file.exists() || !file.canRead()) throw new FileNotFoundException(file.getName()); fis = new FileInputStream(file); _idled = false; _hashSessionManager.restoreSession(fis, this); didActivate(); // If we are doing period saves, then there is no point deleting at this point if (_hashSessionManager._savePeriodMs == 0) file.delete(); } catch (Exception e) { LOG.warn("Problem de-idling session " + super.getId(), e); IO.close(fis); invalidate(); } } }