@Override public void write(OutputStream outputStream) throws WebApplicationException { Exception e = null; CountingOutputStream os = new CountingOutputStream(outputStream); try { // json serializer will always close the yielder jsonWriter.writeValue(os, yielder); os.flush(); // Some types of OutputStream suppress flush errors in the .close() method. os.close(); } catch (Exception ex) { e = ex; log.error(ex, "Unable to send query response."); throw Throwables.propagate(ex); } finally { Thread.currentThread().setName(currThreadName); queryLifecycle.emitLogsAndMetrics(e, req.getRemoteAddr(), os.getCount()); if (e == null) { successfulQueryCount.incrementAndGet(); } else { failedQueryCount.incrementAndGet(); } } } },
@Override public void close() throws IOException { countingOutputStream.close(); }
@Override public void close() throws IOException { countingOutputStream.close(); }
void close() { _lock.lock(); try { if (!_closed) { _closed = true; if (_auditLogOut != null) { _auditLogOut.close(); } if (_auditsWritten != 0) { renameClosedLogFile(_auditLogFile); } } } catch (IOException e) { _log.warn("Failed to close log file", e); } finally { _openAuditOutputs.remove(_batchTime, this); _lock.unlock(); } }
void close() { _lock.lock(); try { if (!_closed) { _closed = true; if (_auditLogOut != null) { _auditLogOut.close(); } if (_auditsWritten != 0) { renameClosedLogFile(_auditLogFile); } } } catch (IOException e) { _log.warn("Failed to close log file", e); } finally { _openAuditOutputs.remove(_batchTime, this); _lock.unlock(); } }
private OutputStream getCurrentTarget() throws IOException { if (currentTarget == null) { currentTarget = new CountingOutputStream(outputFactory.get()); } else if (currentTarget.getCount() >= byteSoftLimit) { LOGGER.info( String.format("Closing stream and opening a new one, reached %,d bytes.\n", currentTarget.getCount())); currentTarget.close(); currentTarget = new CountingOutputStream(outputFactory.get()); } return currentTarget; }
private OutputStream getCurrentTarget() throws IOException { if (currentTarget == null) { currentTarget = new CountingOutputStream(outputFactory.get()); } else if (currentTarget.getCount() >= byteSoftLimit) { LOGGER.info( String.format("Closing stream and opening a new one, reached %,d bytes.\n", currentTarget.getCount())); currentTarget.close(); currentTarget = new CountingOutputStream(outputFactory.get()); } return currentTarget; }
@Override public void write(OutputStream outputStream) throws IOException, WebApplicationException { Exception e = null; CountingOutputStream os = new CountingOutputStream(outputStream); try { // json serializer will always close the yielder jsonWriter.writeValue(os, yielder); os.flush(); // Some types of OutputStream suppress flush errors in the .close() method. os.close(); } catch (Exception ex) { e = ex; log.error(ex, "Unable to send query response."); throw Throwables.propagate(ex); } finally { Thread.currentThread().setName(currThreadName); queryLifecycle.emitLogsAndMetrics(e, req.getRemoteAddr(), os.getCount()); if (e == null) { successfulQueryCount.incrementAndGet(); } else { failedQueryCount.incrementAndGet(); } } } },
@Override public void write(OutputStream outputStream) throws WebApplicationException { Exception e = null; CountingOutputStream os = new CountingOutputStream(outputStream); try { // json serializer will always close the yielder jsonWriter.writeValue(os, yielder); os.flush(); // Some types of OutputStream suppress flush errors in the .close() method. os.close(); } catch (Exception ex) { e = ex; log.error(ex, "Unable to send query response."); throw Throwables.propagate(ex); } finally { Thread.currentThread().setName(currThreadName); queryLifecycle.emitLogsAndMetrics(e, req.getRemoteAddr(), os.getCount()); if (e == null) { successfulQueryCount.incrementAndGet(); } else { failedQueryCount.incrementAndGet(); } } } },
@Override public void close() throws IOException { headerOut.close(); valuesOut.close(); final long numBytesWritten = headerOut.getCount() + valuesOut.getCount(); Preconditions.checkState( headerOut.getCount() == (numWritten * 4), "numWritten[%s] number of rows should have [%s] bytes written to headerOut, had[%s]", numWritten, numWritten * 4, headerOut.getCount() ); Preconditions.checkState( numBytesWritten < Integer.MAX_VALUE, "Wrote[%s] bytes, which is too many.", numBytesWritten ); OutputStream metaOut = ioPeon.makeOutputStream(makeFilename("meta")); try { metaOut.write(0x1); metaOut.write(objectsSorted ? 0x1 : 0x0); metaOut.write(Ints.toByteArray((int) numBytesWritten + 4)); metaOut.write(Ints.toByteArray(numWritten)); } finally { metaOut.close(); } }
@Override public ExternalResourceWriteResult put(ReadableContent location) { try { if (!localFile.canWrite()) { localFile.delete(); } Files.createParentDirs(localFile); InputStream input = location.open(); try { CountingOutputStream output = new CountingOutputStream(new FileOutputStream(localFile)); try { IOUtils.copyLarge(input, output); } finally { output.close(); } return new ExternalResourceWriteResult(output.getCount()); } finally { input.close(); } } catch (IOException e) { throw ResourceExceptions.putFailed(getURI(), e); } }
new HeaderSerializer().write(header, new LittleEndianDataOutputStream(out)); fileOut.sync(); out.close();