private DataSource getDataSource(Id dsRef) { DataSource source = localServer.getDataSource(dsRef); if ( source == null ) throw new DeltaNotFoundException("No such data source: " + dsRef); return source; }
/** Return an {@code InputStream} to data for {@code idx}. * The {@code InputStream} is not buffered. * The caller is responsible for closing the {@code InputStream}. */ public InputStream open(long idx) { Path path = filename(idx); try { return Files.newInputStream(path); } catch (NoSuchFileException ex) { throw new DeltaNotFoundException(ex.getMessage()); } catch (IOException ex) { throw IOX.exception(ex); } }
/** Convert to original exception. */ public static DeltaHttpException extract(DeltaHttpException ex) { int statusCode = ex.getStatusCode(); String msg = ex.getMessage(); switch(statusCode) { case HttpSC.BAD_REQUEST_400: return new DeltaBadRequestException(msg); case HttpSC.NOT_FOUND_404: return new DeltaNotFoundException(msg); case HttpSC.UNAUTHORIZED_401: return new DeltaNotRegisteredException(msg); case HttpSC.FORBIDDEN_403: default: return ex; } }
/** Retrieve a patch by patchId. */ @Override public RDFPatch fetch(Id dsRef, Id patchId) { checkLink(); DataSource source = getDataSourceOrNull(dsRef); if ( source == null ) return null; RDFPatch patch = source.getPatchLog().fetch(patchId); if ( patch == null ) throw new DeltaNotFoundException("No such patch: " + patchId); FmtLog.info(LOG, "fetch: Dest=%s, Patch=%s", source, patchId); return patch; }