/** * Wraps the given input stream into a {@link ReleasableInputStream} if * necessary. Note if the given input stream is a {@link FileInputStream}, a * {@link ResettableInputStream} which is a specific subclass of * {@link ReleasableInputStream} will be returned. */ public static ReleasableInputStream wrap(InputStream is) { if (is instanceof ReleasableInputStream) return (ReleasableInputStream)is; // already wrapped if (is instanceof FileInputStream) return ResettableInputStream.newResettableInputStream((FileInputStream)is); return new ReleasableInputStream(is); } }
/** * Used to truly release the underlying resources. */ private void doRelease() { try { in.close(); } catch (Exception ex) { if (log.isDebugEnabled()) log.debug("FYI", ex); } if (in instanceof Releasable) { // This allows any underlying stream that has the close operation // disabled to be truly released Releasable r = (Releasable)in; r.release(); } abortIfNeeded(); }
/** * If {@link #closeDisabled} is false, closes this input stream and releases * any system resources associated with the stream. Otherwise, this method * does nothing. */ @Override public final void close() { if (!closeDisabled) doRelease(); }
/** * Retrieve an input stream to the subset of the S3 object that matched the query. This is equivalent to loading the content * of all {@link SelectObjectContentEvent.RecordsEvent}s into an {@link InputStream}. This will lazily-load the content from * S3, minimizing the amount of memory used. * * Unlike {@link #getRecordsInputStream()}, this allows you to provide a "listener" {@link SelectObjectContentEventVisitor} * that intercepts the events returned by S3 while the thread that called {@link SelectRecordsInputStream#read()} blocks * waiting for S3 to return a response. * * This will raise a runtime exception if {@link #getAllEvents()}, {@link #visitAllEvents(SelectObjectContentEventVisitor)} * or {@link #getEventsIterator()} have already been used. * * Like all streams, you should {@link SelectRecordsInputStream#close()} it after the content has been read. This * is equivalent to calling {@link #close()} on this {@link SelectObjectContentEventStream}. * * @param listener A visitor for monitoring the progress of the query between {@link RecordsEvent}s. * @see #getRecordsInputStream() */ public SelectRecordsInputStream getRecordsInputStream(SelectObjectContentEventVisitor listener) throws SelectObjectContentEventException { InputStream recordInputStream = new SequenceInputStream(new EventStreamEnumeration(getEventsIterator(), listener)); // Ignore close() calls to the record stream. The sequence input stream would read the whole stream to close all of the // streams in the enum, and the streams in the enum aren't needed because they're byte array input streams. recordInputStream = ReleasableInputStream.wrap(recordInputStream).disableClose(); return new SelectRecordsInputStream(recordInputStream, inputStream); }
public UploadPartRequestFactory(PutObjectRequest origReq, String uploadId, long optimalPartSize) { this.origReq = origReq; this.uploadId = uploadId; this.optimalPartSize = optimalPartSize; this.bucketName = origReq.getBucketName(); this.key = origReq.getKey(); this.file = TransferManagerUtils.getRequestFile(origReq); this.remainingBytes = TransferManagerUtils.getContentLength(origReq); this.sseCustomerKey = origReq.getSSECustomerKey(); this.totalNumberOfParts = (int) Math.ceil((double) this.remainingBytes / this.optimalPartSize); if (origReq.getInputStream() != null) { wrappedStream = ReleasableInputStream.wrap(origReq.getInputStream()); } }
: ReleasableInputStream.wrap(toBeClosed).disableClose(); request.setContent(notCloseable); try {
isCurr = isOrig == null ? null : ReleasableInputStream.wrap(isOrig); } else { isCurr = new ResettableInputStream(fileOrig);
/** * Closes the underlying stream file and releases any system resources associated. */ @Override public final void release() { doRelease(); }
: ReleasableInputStream.wrap(toBeClosed).disableClose(); request.setContent(notCloseable); try {
isCurr = ReleasableInputStream.wrap(isCurr);
/** * Wraps the given input stream into a {@link ReleasableInputStream} if * necessary. Note if the given input stream is a {@link FileInputStream}, a * {@link ResettableInputStream} which is a specific subclass of * {@link ReleasableInputStream} will be returned. */ public static ReleasableInputStream wrap(InputStream is) { if (is instanceof ReleasableInputStream) return (ReleasableInputStream)is; // already wrapped if (is instanceof FileInputStream) return ResettableInputStream.newResettableInputStream((FileInputStream)is); return new ReleasableInputStream(is); } }
/** * Used to truly release the underlying resources. */ private void doRelease() { try { in.close(); } catch (Exception ex) { if (log.isDebugEnabled()) log.debug("FYI", ex); } if (in instanceof Releasable) { // This allows any underlying stream that has the close operation // disabled to be truly released Releasable r = (Releasable)in; r.release(); } abortIfNeeded(); }
/** * Closes the underlying stream file and releases any system resources associated. */ @Override public final void release() { doRelease(); }
: ReleasableInputStream.wrap(toBeClosed).disableClose(); request.setContent(notCloseable); try {
input = ReleasableInputStream.wrap(input); } else {
/** * Wraps the given input stream into a {@link ReleasableInputStream} if * necessary. Note if the given input stream is a {@link FileInputStream}, a * {@link ResettableInputStream} which is a specific subclass of * {@link ReleasableInputStream} will be returned. */ public static ReleasableInputStream wrap(InputStream is) { if (is instanceof ReleasableInputStream) { return (ReleasableInputStream)is; // already wrapped } if (is instanceof FileInputStream) { return ResettableInputStream.newResettableInputStream((FileInputStream)is); } return new ReleasableInputStream(is); } }
/** * Used to truly release the underlying resources. */ private void doRelease() { try { in.close(); } catch (final Exception ex) { if (log.isDebugEnabled()) { log.debug("FYI", ex); } } if (in instanceof Releasable) { // This allows any underlying stream that has the close operation // disabled to be truly released final Releasable r = (Releasable)in; r.release(); } abortIfNeeded(); }
/** * Closes the underlying stream file and releases any system resources associated. */ @Override public final void release() { doRelease(); }
isCurr = isOrig == null ? null : ReleasableInputStream.wrap(isOrig); } else { isCurr = new ResettableInputStream(fileOrig);
/** * Wraps the given input stream into a {@link ReleasableInputStream} if * necessary. Note if the given input stream is a {@link FileInputStream}, a * {@link ResettableInputStream} which is a specific subclass of * {@link ReleasableInputStream} will be returned. */ public static ReleasableInputStream wrap(InputStream is) { if (is instanceof ReleasableInputStream) return (ReleasableInputStream)is; // already wrapped if (is instanceof FileInputStream) return ResettableInputStream.newResettableInputStream((FileInputStream)is); return new ReleasableInputStream(is); } }