public static String getKey(String key) throws KeyNotFoundException { String value = getOptionalKey(key); if (value.equals("")) throw new KeyNotFoundException(key); return value; } public static String getOptionalKey(String key) { if (key.equals("something")) { return "great"; } else { return ""; } }
public static String getKey(String key) throws KeyNotFoundException { return getOptionalKey(key).orElseThrow(() -> new KeyNotFoundException(key)); }
class final ResultHoder { String result; public void setResult(String result) { this.result = result; } public String getResult() { return this.result; } } public static void getKey(String key, ResultHolder result) throws KeyNotFoundException { if (key.equals("something")) { result.setResult("great"); return; } else { result.setResult(""); throw new KeyNotFoundException(); } }
public Object createOrPropagate(Throwable t) throws Exception { if (contains404(checkNotNull(t, "throwable"))) throw new KeyNotFoundException(t); throw propagate(t); }
public Object createOrPropagate(Throwable t) throws Exception { if (contains404(checkNotNull(t, "throwable"))) throw new KeyNotFoundException(t); throw propagate(t); }
public Object createOrPropagate(Throwable t) throws Exception { if (contains404(checkNotNull(t, "throwable"))) throw new KeyNotFoundException(t); throw propagate(t); } }
@Override public BlobAccess getBlobAccess(String containerName, String blobName) { Map<String, BlobAccess> map = containerToBlobAccess.get(containerName); if (map == null) { throw new ContainerNotFoundException(containerName, "in getBlobAccess"); } BlobAccess access = map.get(blobName); if (access == null) { throw new KeyNotFoundException(containerName, blobName, "in getBlobAccess"); } return access; }
@Override public BlobAccess getBlobAccess(String containerName, String blobName) { Map<String, BlobAccess> map = containerToBlobAccess.get(containerName); if (map == null) { throw new ContainerNotFoundException(containerName, "in getBlobAccess"); } BlobAccess access = map.get(blobName); if (access == null) { throw new KeyNotFoundException(containerName, blobName, "in getBlobAccess"); } return access; }
@Override public BlobAccess getBlobAccess(String containerName, String blobName) { Map<String, BlobAccess> map = containerToBlobAccess.get(containerName); if (map == null) { throw new ContainerNotFoundException(containerName, "in getBlobAccess"); } BlobAccess access = map.get(blobName); if (access == null) { throw new KeyNotFoundException(containerName, blobName, "in getBlobAccess"); } return access; }
public Object createOrPropagate(Throwable t) throws Exception { if (contains404(checkNotNull(t, "throwable"))) throw new KeyNotFoundException(t); throw propagate(t); } }
public Object createOrPropagate(Throwable t) throws Exception { if (contains404(checkNotNull(t, "throwable"))) throw new KeyNotFoundException(t); throw propagate(t); }
public Object createOrPropagate(Throwable t) throws Exception { if (contains404(checkNotNull(t, "throwable"))) throw new KeyNotFoundException(t); throw propagate(t); } }
public Object createOrPropagate(Throwable t) throws Exception { if (contains404(checkNotNull(t, "throwable"))) throw new KeyNotFoundException(t); throw propagate(t); } }
@Override public BlobAccess getBlobAccess(String containerName, String blobName) { Map<String, BlobAccess> map = containerToBlobAccess.get(containerName); if (map == null) { throw new ContainerNotFoundException(containerName, "in getBlobAccess"); } BlobAccess access = map.get(blobName); if (access == null) { throw new KeyNotFoundException(containerName, blobName, "in getBlobAccess"); } return access; }
@Override protected Object doExecute() throws Exception { BlobStore blobStore = getBlobStore(); if (!blobStore.blobExists(containerName, blobName)) { throw new KeyNotFoundException(containerName, blobName, "while checking existence"); } return null; } }
protected Exception refineException(HttpCommand command, HttpResponse response, Exception exception, AzureStorageError error, String message) { switch (response.getStatusCode()) { case 404: if (!command.getCurrentRequest().getMethod().equals("DELETE")) { exception = new ResourceNotFoundException(message, exception); List<String> parts = Lists.newArrayList(Splitter.on('/').split( command.getCurrentRequest().getEndpoint().getPath())); parts.remove(""); if (!parts.isEmpty()) { String container = parts.remove(0); String query = command.getCurrentRequest().getEndpoint().getQuery(); if (query != null && query.indexOf("container") != -1) { exception = new ContainerNotFoundException(container, message); } else { exception = new KeyNotFoundException(container, Joiner.on('/').join(parts), message); } } } return exception; default: return super.refineException(command, response, exception, error, message); } } }
private static Exception refineException(B2Error error, Exception exception) { if ("bad_bucket_id".equals(error.code())) { return new ContainerNotFoundException(exception); } else if ("bad_json".equals(error.code())) { return new IllegalArgumentException(error.message(), exception); } else if ("bad_request".equals(error.code())) { return new IllegalArgumentException(error.message(), exception); } else if ("file_not_present".equals(error.code())) { return new KeyNotFoundException(exception); } else if ("not_found".equals(error.code())) { return new ResourceNotFoundException(error.message(), exception); } else { return exception; } }
private static Exception refineException(B2Error error, Exception exception) { if ("bad_bucket_id".equals(error.code())) { return new ContainerNotFoundException(exception); } else if ("bad_json".equals(error.code())) { return new IllegalArgumentException(error.message(), exception); } else if ("bad_request".equals(error.code())) { return new IllegalArgumentException(error.message(), exception); } else if ("file_not_present".equals(error.code())) { return new KeyNotFoundException(exception); } else if ("not_found".equals(error.code())) { return new ResourceNotFoundException(error.message(), exception); } else { return exception; } }
private static Exception refineException(B2Error error, Exception exception) { if ("bad_bucket_id".equals(error.code())) { return new ContainerNotFoundException(exception); } else if ("bad_json".equals(error.code())) { return new IllegalArgumentException(error.message(), exception); } else if ("bad_request".equals(error.code())) { return new IllegalArgumentException(error.message(), exception); } else if ("file_not_present".equals(error.code())) { return new KeyNotFoundException(exception); } else if ("not_found".equals(error.code())) { return new ResourceNotFoundException(error.message(), exception); } else { return exception; } }
private static Exception refineException(B2Error error, Exception exception) { if ("bad_bucket_id".equals(error.code())) { return new ContainerNotFoundException(exception); } else if ("bad_json".equals(error.code())) { return new IllegalArgumentException(error.message(), exception); } else if ("bad_request".equals(error.code())) { return new IllegalArgumentException(error.message(), exception); } else if ("file_not_present".equals(error.code())) { return new KeyNotFoundException(exception); } else if ("not_found".equals(error.code())) { return new ResourceNotFoundException(error.message(), exception); } else { return exception; } }