/** * Convert an exception to a data store exception. * * @param cause the message * @param e the root cause * @return the data store exception */ protected DataStoreException convert(String cause, Exception e) { log.warn(cause, e); if (e instanceof DataStoreException) { return (DataStoreException) e; } else { return new DataStoreException(cause, e); } }
/** * Open the stream if required. * * @throws IOException */ protected void openStream() throws IOException { if (endOfStream) { throw new EOFException(); } if (in == null) { try { in = store.openStream(this, identifier); } catch (DataStoreException e) { IOException e2 = new IOException(e.getMessage()); e2.initCause(e); throw e2; } } }
@Test public void testBackendAddMetadataRecordFileNotFoundThrowsDataStoreException() throws IOException { File testFile = folder.newFile(); copyInputStreamToFile(randomStream(0, 10), testFile); testFile.delete(); try { backend.addMetadataRecord(testFile, "name"); fail(); } catch (DataStoreException e) { assertTrue(e.getCause() instanceof FileNotFoundException); } }
@Override public InputStream getInputStream(String blobId) throws IOException { try { return store.get(blobId).getStream(); } catch (DataStoreException e) { e.printStackTrace(); } return null; }
@Test public void testBackendWriteRecordFileNotFoundThrowsException() throws IOException, NoSuchAlgorithmException { File testFile = folder.newFile(); copyInputStreamToFile(randomStream(0, 10), testFile); DataIdentifier identifier = new DataIdentifier(getIdForInputStream(new FileInputStream(testFile))); assertTrue(testFile.delete()); try { backend.write(identifier, testFile); fail(); } catch (DataStoreException e) { assertTrue(e.getCause() instanceof FileNotFoundException); } }
/** * Convert an exception to a data store exception. * * @param cause the message * @param e the root cause * @return the data store exception */ protected DataStoreException convert(String cause, Exception e) { log.warn(cause, e); if (e instanceof DataStoreException) { return (DataStoreException) e; } else { return new DataStoreException(cause, e); } }
@Test public void testBackendAddMetadataRecordFileNotFoundThrowsDataStoreException() throws IOException { SharedDataStore fds = dataStore; File testFile = folder.newFile(); copyInputStreamToFile(randomStream(0, 10), testFile); testFile.delete(); try { fds.addMetadataRecord(testFile, "name"); fail(); } catch (DataStoreException e) { assertTrue(e.getCause() instanceof FileNotFoundException); } }
/** * Open the stream if required. * * @throws IOException */ protected void openStream() throws IOException { if (endOfStream) { throw new EOFException(); } if (in == null) { try { in = store.openStream(this, identifier); } catch (DataStoreException e) { IOException e2 = new IOException(e.getMessage()); e2.initCause(e); throw e2; } } }
/** * Convert an exception to a data store exception. * * @param cause the message * @param e the root cause * @return the data store exception */ protected DataStoreException convert(String cause, Exception e) { log.warn(cause, e); if (e instanceof DataStoreException) { return (DataStoreException) e; } else { return new DataStoreException(cause, e); } }
/** * Open the stream if required. * * @throws IOException */ protected void openStream() throws IOException { if (endOfStream) { throw new EOFException(); } if (in == null) { try { in = store.openStream(this, identifier); } catch (DataStoreException e) { IOException e2 = new IOException(e.getMessage()); e2.initCause(e); throw e2; } } }
@Override public void addMetadataRecord(File input, String name) throws DataStoreException { try { File file = new File(fsPathDir, name); FileUtils.copyFile(input, file); } catch (IOException e) { LOG.error("Exception while adding metadata record file {} with name {}, {}", input, name, e); throw new DataStoreException("Could not add root record", e); } }
/** * Get the last modified date of a file. * * @param file the file * @return the last modified date * @throws DataStoreException if reading fails */ private static long getLastModified(File file) throws DataStoreException { long lastModified = file.lastModified(); if (lastModified == 0) { throw new DataStoreException("Failed to read record modified date: " + file.getAbsolutePath()); } return lastModified; }
/** * Get the last modified date of a file. * * @param file the file * @return the last modified date * @throws DataStoreException if reading fails */ private static long getLastModified(File file) throws DataStoreException { long lastModified = file.lastModified(); if (lastModified == 0) { throw new DataStoreException("Failed to read record modified date: " + file.getAbsolutePath()); } return lastModified; }
/** * Get the last modified date of a file. * * @param file the file * @return the last modified date * @throws DataStoreException if reading fails */ private static long getLastModified(File file) throws DataStoreException { long lastModified = file.lastModified(); if (lastModified == 0) { throw new DataStoreException( "Failed to read record modified date: " + file.getAbsolutePath()); } return lastModified; }
/** * Get the last modified date of a file. * * @param file the file * @return the last modified date * @throws DataStoreException if reading fails */ private static long getLastModified(File file) throws DataStoreException { long lastModified = file.lastModified(); if (lastModified == 0) { throw new DataStoreException("Failed to read record modified date: " + file.getAbsolutePath()); } return lastModified; }
/** * Get the last modified date of a file. * @param file the file * @return the last modified date * @throws DataStoreException if reading fails */ private static long getLastModified(File file) throws DataStoreException { long lastModified = file.lastModified(); if (lastModified == 0) { throw new DataStoreException( "Failed to read record modified date: " + file.getAbsolutePath()); } return lastModified; }
/** * Get the last modified date of a file. * @param file the file * @return the last modified date * @throws DataStoreException if reading fails */ private static long getLastModified(File file) throws DataStoreException { long lastModified = file.lastModified(); if (lastModified == 0) { throw new DataStoreException( "Failed to read record modified date: " + file.getAbsolutePath()); } return lastModified; }
/** * Get the last modified date of a file. * * @param file the file * @return the last modified date * @throws DataStoreException if reading fails */ private static long getLastModified(File file) throws DataStoreException { long lastModified = file.lastModified(); if (lastModified == 0) { throw new DataStoreException( "Failed to read record modified date: " + file.getAbsolutePath()); } return lastModified; }
/** * Get the last modified date of a file. * @param file the file * @return the last modified date * @throws DataStoreException if reading fails */ private static long getLastModified(File file) throws DataStoreException { long lastModified = file.lastModified(); if (lastModified == 0) { throw new DataStoreException( "Failed to read record modified date: " + file.getAbsolutePath()); } return lastModified; }
/** * Get the last modified date of a file. * * @param file the file * @return the last modified date * @throws DataStoreException if reading fails */ private static long getLastModified(File file) throws DataStoreException { long lastModified = file.lastModified(); if (lastModified == 0) { throw new DataStoreException( "Failed to read record modified date: " + file.getAbsolutePath()); } return lastModified; }