/** * Buffer input stream if possible. * * @param content Input stream to buffer * @return SdkBufferedInputStream if possible, otherwise original input stream. */ private InputStream buffer(InputStream content) { if (!content.markSupported()) { content = new SdkBufferedInputStream(content); } return content; }
/** * Aborts with subclass specific abortion logic executed if needed. * Note the interrupted status of the thread is cleared by this method. * @throws AbortedException if found necessary. */ protected final void abortIfNeeded() { if (shouldAbort()) { abort(); // execute subclass specific abortion logic throw new AbortedException(); } }
@Override public void close() throws IOException { super.close(); abortIfNeeded(); }
/** * Buffer input stream if possible. * * @param content Input stream to buffer * @return SdkBufferedInputStream if possible, otherwise original input stream. */ private InputStream buffer(InputStream content) { if (!content.markSupported()) { content = new SdkBufferedInputStream(content); } return content; }
@Override public int available() throws IOException { abortIfNeeded(); return super.available(); }
/** * Aborts with subclass specific abortion logic executed if needed. * Note the interrupted status of the thread is cleared by this method. * @throws AbortedException if found necessary. */ protected final void abortIfNeeded() { if (shouldAbort()) { abort(); // execute subclass specific abortion logic throw new AbortedException(); } }
/** * Buffer input stream if possible. * * @param content Input stream to buffer * @return SdkBufferedInputStream if possible, otherwise original input stream. */ private InputStream buffer(InputStream content) { if (!content.markSupported()) { content = new SdkBufferedInputStream(content); } return content; }
@Override public void mark(int readlimit) { abortIfNeeded(); super.mark(readlimit); }
/** * Aborts with subclass specific abortion logic executed if needed. * Note the interrupted status of the thread is cleared by this method. * @throws AbortedException if found necessary. */ protected final void abortIfNeeded() { if (shouldAbort()) { abort(); // execute subclass specific abortion logic throw new AbortedException(); } }
@Override public void copyObjectToStream(String bucket, String key, OutputStream out) { checkNotBlank(bucket, "bucket"); checkNotBlank(key, "key"); checkNotNull(out, "out"); S3Object object = client.getObject(bucket, key); int bufferSize = (int) min(this.bufferSize, object.getObjectMetadata().getContentLength()); Optional<IOException> exception = absent(); for (int i = 0; i < this.automaticRetries; i++) { InputStream in = null; try { in = new SdkBufferedInputStream(object.getObjectContent(), bufferSize); copyLarge(in, out); exception = absent(); break; } catch (IOException e) { exception = Optional.of(e); } finally { closeQuietly(in); } } if (exception.isPresent()) { throw illegalState(exception.get()); } }
@Override public void reset() throws IOException { abortIfNeeded(); super.reset(); }
String key = tenantType.getTenant() + keyPrefix + fileName; try (SdkBufferedInputStream stream = new SdkBufferedInputStream(new FileInputStream(file), (int) (file.length() + 100))) { String type = Mimetypes.getInstance().getMimetype(file.getName());
@Override public int read() throws IOException { abortIfNeeded(); return super.read(); }
String key = tenantType.getTenant() + keyPrefix + fileName; try (SdkBufferedInputStream stream = new SdkBufferedInputStream(new FileInputStream(file), (int) (file.length() + 100))) { String type = Mimetypes.getInstance().getMimetype(file.getName());
@Override public int read(byte b[], int off, int len) throws IOException { abortIfNeeded(); return super.read(b, off, len); }
public String saveFile(final FileUploadType file) throws ServiceException { SdkBufferedInputStream stream = null; GeneratePresignedUrlRequest request; try { stream = new SdkBufferedInputStream(file.getFile().getInputStream(), (int) (file.getFile().getSize() + 100)); String type = Mimetypes.getInstance().getMimetype(file.getFile().getOriginalFilename()); String key = getFileKey(file); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentType(type); metadata.setContentLength(file.getFile().getSize()); PutObjectRequest putRequest = new PutObjectRequest(getAmazonType().getS3Bucket(), key, stream, metadata); getAmazonType().getAmazonS3().putObject(putRequest); getAmazonType().getAmazonS3().setObjectAcl(getAmazonType().getS3Bucket(), key, CannedAccessControlList.PublicRead); request = new GeneratePresignedUrlRequest(getAmazonType().getS3Bucket(), key); } catch (IOException e) { throw new AWSException("Can't save file to Amazone", e); } finally { IOUtils.closeQuietly(stream); } return getAmazonType().getAmazonS3().generatePresignedUrl(request).toString().split("\\?")[0]; }
@Override public boolean markSupported() { abortIfNeeded(); return super.markSupported(); } }
@Override public long skip(long n) throws IOException { abortIfNeeded(); return super.skip(n); }
@Override public int read(byte b[], int off, int len) throws IOException { abortIfNeeded(); return super.read(b, off, len); }
@Override public void close() throws IOException { super.close(); abortIfNeeded(); }