@Override public URI getStashRoot() throws StashNotAvailableException { if (!_stashRootDirectory.isPresent()) { throw new StashNotAvailableException(); } return _stashRootDirectory.get(); }
StashNotAvailableException.class.getName().equals(exceptionType)) { if (response.hasEntity()) { return (RuntimeException) response.getEntity(StashNotAvailableException.class).initCause(e); } else { return (RuntimeException) new StashNotAvailableException().initCause(e);
StashNotAvailableException.class.getName().equals(exceptionType)) { if (response.hasEntity()) { return (RuntimeException) response.getEntity(StashNotAvailableException.class).initCause(e); } else { return (RuntimeException) new StashNotAvailableException().initCause(e);
@Override public URI getStashRoot() throws StashNotAvailableException { if (!_stashRootDirectory.isPresent()) { throw new StashNotAvailableException(); } return _stashRootDirectory.get(); }
private String readFirstLineFromS3File(String bucket, String path) { S3Object s3Object; try { // In the unlikely case that someone replaced the Stash file with a malicious file intended to cause // a memory overrun restrict the file contents fetched to a reasonably high limit. s3Object = _s3.getObject(new GetObjectRequest(bucket, path).withRange(0, 2048)); } catch (AmazonS3Exception e) { if (e.getStatusCode() == 404) { throw new StashNotAvailableException(); } throw e; } try (BufferedReader in = new BufferedReader(new InputStreamReader(s3Object.getObjectContent(), Charsets.UTF_8))) { return in.readLine(); } catch (IOException e) { throw Throwables.propagate(e); } }
private String readFirstLineFromS3File(String bucket, String path) { S3Object s3Object; try { // In the unlikely case that someone replaced the Stash file with a malicious file intended to cause // a memory overrun restrict the file contents fetched to a reasonably high limit. s3Object = _s3.getObject(new GetObjectRequest(bucket, path).withRange(0, 2048)); } catch (AmazonS3Exception e) { if (e.getStatusCode() == 404) { throw new StashNotAvailableException(); } throw e; } try (BufferedReader in = new BufferedReader(new InputStreamReader(s3Object.getObjectContent(), Charsets.UTF_8))) { return in.readLine(); } catch (IOException e) { throw Throwables.propagate(e); } }
/** * This method is like {@link #lockToLatest()} except that the caller requests a specific Stash time. * @throws StashNotAvailableException Thrown if no Stash is available for the given time */ public void lockToStashCreatedAt(Date creationTime) throws StashNotAvailableException { String stashDirectory = StashUtil.getStashDirectoryForCreationTime(creationTime); // The following call will raise an AmazonS3Exception if the file cannot be read try (S3Object s3Object = _s3.getObject(_bucket, String.format("%s/%s/%s", _rootPath, stashDirectory, StashUtil.SUCCESS_FILE))) { _lockedLatest = String.format("%s/%s", _rootPath, stashDirectory); } catch (AmazonS3Exception e) { if (e.getStatusCode() == 404 || // The following conditions indicate the file has already been moved to Glacier (e.getStatusCode() == 403 && "InvalidObjectState".equals(e.getErrorCode()))) { throw new StashNotAvailableException(); } throw e; } catch (IOException e) { // Shouldn't happen since the file is never actually read } }
/** * This method is like {@link #lockToLatest()} except that the caller requests a specific Stash time. * @throws StashNotAvailableException Thrown if no Stash is available for the given time */ public void lockToStashCreatedAt(Date creationTime) throws StashNotAvailableException { String stashDirectory = StashUtil.getStashDirectoryForCreationTime(creationTime); // The following call will raise an AmazonS3Exception if the file cannot be read try (S3Object s3Object = _s3.getObject(_bucket, String.format("%s/%s/%s", _rootPath, stashDirectory, StashUtil.SUCCESS_FILE))) { _lockedLatest = String.format("%s/%s", _rootPath, stashDirectory); } catch (AmazonS3Exception e) { if (e.getStatusCode() == 404 || // The following conditions indicate the file has already been moved to Glacier (e.getStatusCode() == 403 && "InvalidObjectState".equals(e.getErrorCode()))) { throw new StashNotAvailableException(); } throw e; } catch (IOException e) { // Shouldn't happen since the file is never actually read } }