public static void deleteQuietly(Location location) { deleteQuietly(location, false); }
public static void deleteQuietly(Location location) { deleteQuietly(location, false); }
/** * Deletes the content of the given location, but keeping the location itself. */ public static void deleteContent(Location location) { try { for (Location child : location.list()) { deleteQuietly(child, true); } } catch (IOException e) { LOG.error("IOException while deleting content of {}", location, e); } }
@Override public void cancel() { Closeables.closeQuietly(writer); Locations.deleteQuietly(Locations.getParent(eventFile), true); }
/** * Deletes the content of the given location, but keeping the location itself. */ public static void deleteContent(Location location) { try { for (Location child : location.list()) { deleteQuietly(child, true); } } catch (IOException e) { LOG.error("IOException while deleting content of {}", location, e); } }
private Runnable createCleanupTask(final Object...resources) { return () -> { for (Object resource : resources) { if (resource == null) { continue; } try { if (resource instanceof File) { if (((File) resource).isDirectory()) { DirUtils.deleteDirectoryContents((File) resource); } else { ((File) resource).delete(); } } else if (resource instanceof Location) { Locations.deleteQuietly((Location) resource, true); } else if (resource instanceof AutoCloseable) { ((AutoCloseable) resource).close(); } else if (resource instanceof Runnable) { ((Runnable) resource).run(); } } catch (Throwable t) { LOG.warn("Exception when cleaning up resource {}", resource, t); } } }; }
private Runnable createCleanupTask(final Object...resources) { return () -> { for (Object resource : resources) { if (resource == null) { continue; } try { if (resource instanceof File) { if (((File) resource).isDirectory()) { DirUtils.deleteDirectoryContents((File) resource); } else { ((File) resource).delete(); } } else if (resource instanceof Location) { Locations.deleteQuietly((Location) resource, true); } else if (resource instanceof AutoCloseable) { ((AutoCloseable) resource).close(); } else if (resource instanceof Runnable) { ((Runnable) resource).run(); } } catch (Throwable t) { LOG.warn("Exception when cleaning up resource {}", resource, t); } } }; }
@AfterClass public static void tearDown() { Locations.deleteQuietly(namespaceHomeLocation, true); } }
@Override public void close() throws IOException { try { writer.flush(); streamWriter.appendFile(streamConfig.getStreamId(), eventFile, indexFile, eventCount, writer); } catch (NotFoundException e) { throw Throwables.propagate(e); } finally { Locations.deleteQuietly(Locations.getParent(eventFile), true); } }
private LogFileOutputStream createOutputStream(final LogPathIdentifier identifier, long timestamp) throws IOException { TimeStampLocation location = createLocation(identifier); LogFileOutputStream logFileOutputStream = new LogFileOutputStream( location.getLocation(), filePermissions, syncIntervalBytes, location.getTimeStamp(), new Closeable() { @Override public void close() throws IOException { outputStreamMap.remove(identifier); } }); logFileOutputStream.flush(); LOG.info("Created Avro file at {}", location); // we write meta data after creating output stream, as we want to avoid having meta data for zero-length avro file. // LogFileOutputStream creation writes the schema to the avro file. if meta data write fails, // we then close output stream and delete the file try { fileMetaDataWriter.writeMetaData(identifier, timestamp, location.getTimeStamp(), location.getLocation()); } catch (Throwable e) { // delete created file as there was exception while writing meta data Closeables.closeQuietly(logFileOutputStream); Locations.deleteQuietly(location.getLocation()); throw new IOException(e); } outputStreamMap.put(identifier, logFileOutputStream); return logFileOutputStream; }
private LogFileOutputStream createOutputStream(final LogPathIdentifier identifier, long timestamp) throws IOException { TimeStampLocation location = createLocation(identifier); LogFileOutputStream logFileOutputStream = new LogFileOutputStream( location.getLocation(), filePermissions, syncIntervalBytes, location.getTimeStamp(), new Closeable() { @Override public void close() throws IOException { outputStreamMap.remove(identifier); } }); logFileOutputStream.flush(); LOG.info("Created Avro file at {}", location); // we write meta data after creating output stream, as we want to avoid having meta data for zero-length avro file. // LogFileOutputStream creation writes the schema to the avro file. if meta data write fails, // we then close output stream and delete the file try { fileMetaDataWriter.writeMetaData(identifier, timestamp, location.getTimeStamp(), location.getLocation()); } catch (Throwable e) { // delete created file as there was exception while writing meta data Closeables.closeQuietly(logFileOutputStream); Locations.deleteQuietly(location.getLocation()); throw new IOException(e); } outputStreamMap.put(identifier, logFileOutputStream); return logFileOutputStream; }
} finally { Locations.deleteQuietly(keysDir, true);
} finally { Locations.deleteQuietly(keysDir, true);
private void writeConfig(StreamConfig config) throws IOException { Location configLocation = config.getLocation().append(CONFIG_FILE_NAME); Location tmpConfigLocation = configLocation.getTempFile(null); CharStreams.write(GSON.toJson(config), CharStreams.newWriterSupplier( Locations.newOutputSupplier(tmpConfigLocation), Charsets.UTF_8)); try { // Windows does not allow renaming if the destination file exists so we must delete the configLocation if (OSDetector.isWindows()) { configLocation.delete(); } tmpConfigLocation.renameTo(getConfigLocation(config.getStreamId())); } finally { Locations.deleteQuietly(tmpConfigLocation); } }
@AfterClass public static void tearDown() throws Exception { Services.chainStop(service, opExecutorService, txManager); namespaceAdmin.delete(NamespaceId.DEFAULT); Locations.deleteQuietly(locationFactory.create(NamespaceId.DEFAULT.getNamespace())); }
Locations.deleteQuietly(customlocation);
Locations.deleteQuietly(customlocation);