@Override public void close() { closeQuietly(connector); }
public static void closeQuietly(Closeable... closeables) { for (Closeable c : closeables) { closeQuietly(c); } }
public static void closeQuietly(Closeable... closeables) { for (Closeable c : closeables) { closeQuietly(c); } }
@Override public void run() { try { String line; while ((line = reader.readLine()) != null) { LOGGER.trace(line); stringBuilder.append(line).append(NEW_LINE); } } catch (IOException ignored) { EmptyStatement.ignore(ignored); } finally { closeQuietly(reader); closeQuietly(inputStreamReader); } } }
@Override public void run() { try { String line; while ((line = reader.readLine()) != null) { stringBuilder.append(line).append(NEW_LINE); } } catch (IOException ignored) { EmptyStatement.ignore(ignored); } finally { closeQuietly(reader); closeQuietly(inputStreamReader); } } }
public static String fileAsText(File file) { FileInputStream stream = null; InputStreamReader streamReader = null; BufferedReader reader = null; try { stream = new FileInputStream(file); streamReader = new InputStreamReader(stream); reader = new BufferedReader(streamReader); StringBuilder builder = new StringBuilder(); char[] buffer = new char[READ_BUFFER_SIZE]; int read; while ((read = reader.read(buffer, 0, buffer.length)) > 0) { builder.append(buffer, 0, read); } return builder.toString(); } catch (IOException e) { throw new UncheckedIOException(e); } finally { closeQuietly(reader); closeQuietly(streamReader); closeQuietly(stream); } }
@SuppressFBWarnings("DM_DEFAULT_ENCODING") private static Properties loadProperties(File file) { FileReader reader = null; try { reader = new FileReader(file); Properties properties = new Properties(); properties.load(reader); return properties; } catch (IOException e) { throw new CommandLineExitException(format("Failed to load TestSuite property file [%s]", file.getAbsolutePath()), e); } finally { closeQuietly(reader); } }
static Properties getUserProperties() { FileInputStream inputStream = null; try { Properties properties = new Properties(); File userPropertiesFile = new File(SimulatorProperties.PROPERTIES_FILE_NAME).getAbsoluteFile(); if (!userPropertiesFile.exists()) { return properties; } inputStream = new FileInputStream(userPropertiesFile); properties.load(inputStream); return properties; } catch (IOException e) { throw rethrow(e); } finally { closeQuietly(inputStream); } }
static Properties loadGitProperties(String fileName) { Properties properties = new Properties(); InputStream inputStream = GitInfo.class.getClassLoader().getResourceAsStream(fileName); try { properties.load(inputStream); return properties; } catch (NullPointerException e) { LOGGER.trace("Error while loading Git properties from " + fileName, e); } catch (Exception e) { LOGGER.warn("Error while loading Git properties from " + fileName, e); } finally { closeQuietly(inputStream); } return new UnknownGitProperties(); }
public static String getText(String url) { try { URL website = new URL(url); URLConnection connection = website.openConnection(); InputStreamReader streamReader = null; BufferedReader reader = null; try { streamReader = new InputStreamReader(connection.getInputStream()); reader = new BufferedReader(streamReader); StringBuilder response = new StringBuilder(); String inputLine; while ((inputLine = reader.readLine()) != null) { response.append(inputLine); } return response.toString(); } finally { closeQuietly(reader); closeQuietly(streamReader); } } catch (IOException e) { throw new UncheckedIOException(e); } }
public static void appendText(String text, File file) { checkNotNull(text, "Text can't be null"); checkNotNull(file, "File can't be null"); FileOutputStream stream = null; OutputStreamWriter streamWriter = null; BufferedWriter writer = null; try { stream = new FileOutputStream(file, true); streamWriter = new OutputStreamWriter(stream); writer = new BufferedWriter(streamWriter); writer.append(text); writer.close(); } catch (IOException e) { throw new UncheckedIOException("Could not append text", e); } finally { closeQuietly(writer); closeQuietly(streamWriter); closeQuietly(stream); } }
public static void copy(File file, OutputStream outputStream) { InputStream inputStream = null; try { inputStream = new FileInputStream(file); byte[] buffer = new byte[COPY_BUFFER_SIZE]; while (true) { int readCount = inputStream.read(buffer); if (readCount < 0) { break; } outputStream.write(buffer, 0, readCount); } } catch (IOException e) { throw new UncheckedIOException(e); } finally { closeQuietly(inputStream); } }
public static void copy(File file, OutputStream outputStream) { InputStream inputStream = null; try { inputStream = new FileInputStream(file); byte[] buffer = new byte[COPY_BUFFER_SIZE]; while (true) { int readCount = inputStream.read(buffer); if (readCount < 0) { break; } outputStream.write(buffer, 0, readCount); } } catch (IOException e) { throw new UncheckedIOException(e); } finally { closeQuietly(inputStream); } }
public static void writeText(String text, File file) { checkNotNull(text, "Text can't be null"); checkNotNull(file, "File can't be null"); FileOutputStream stream = null; OutputStreamWriter streamWriter = null; BufferedWriter writer = null; try { stream = new FileOutputStream(file); streamWriter = new OutputStreamWriter(stream); writer = new BufferedWriter(streamWriter); writer.write(text); writer.close(); } catch (IOException e) { throw new UncheckedIOException(e); } finally { closeQuietly(writer); closeQuietly(streamWriter); closeQuietly(stream); } }
public static void writeText(String text, File file) { checkNotNull(text, "Text can't be null"); checkNotNull(file, "File can't be null"); FileOutputStream stream = null; OutputStreamWriter streamWriter = null; BufferedWriter writer = null; try { stream = new FileOutputStream(file); streamWriter = new OutputStreamWriter(stream); writer = new BufferedWriter(streamWriter); writer.write(text); writer.close(); } catch (IOException e) { throw new UncheckedIOException(e); } finally { closeQuietly(writer); closeQuietly(streamWriter); closeQuietly(stream); } }
public static void appendText(String text, File file) { checkNotNull(text, "Text can't be null"); checkNotNull(file, "File can't be null"); FileOutputStream stream = null; OutputStreamWriter streamWriter = null; BufferedWriter writer = null; try { stream = new FileOutputStream(file, true); streamWriter = new OutputStreamWriter(stream); writer = new BufferedWriter(streamWriter); writer.append(text); writer.close(); } catch (IOException e) { throw new UncheckedIOException("Could not append text", e); } finally { closeQuietly(writer); closeQuietly(streamWriter); closeQuietly(stream); } }
void load(File file) { FileInputStream inputStream = null; try { inputStream = new FileInputStream(file); properties.load(inputStream); if (containsKey("HAZELCAST_VERSION_SPEC")) { throw new IOException("'HAZELCAST_VERSION_SPEC' property is deprecated, Use 'VERSION_SPEC' instead."); } } catch (IOException e) { throw rethrow(e); } finally { closeQuietly(inputStream); } }
public static void main(String[] args) throws Exception { CoordinatorRemoteCli cli = null; try { cli = new CoordinatorRemoteCli(args); cli.run(); } catch (Exception e) { System.err.print(e.getMessage()); exitWithError(LOGGER, e.getMessage(), e); } finally { closeQuietly(cli); } }
@Override protected BenchmarkResults doInBackground() throws Exception { FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(file); Map<String, Result> probeResultMap = ProbesResultXmlReader.read(fileInputStream); String filename = getFileName(file); BenchmarkResults benchmarkResults = new BenchmarkResults(filename); for (Map.Entry<String, Result> entry : probeResultMap.entrySet()) { benchmarkResults.addProbeData(entry.getKey(), entry.getValue()); } return benchmarkResults; } finally { closeQuietly(fileInputStream); } }
@Override public void close() { stopTests(); if (client != null) { new TerminateWorkersTask(simulatorProperties, componentRegistry, client).run(); } closeQuietly(client); closeQuietly(connector); stopAgents(LOGGER, bash, simulatorProperties, componentRegistry); if (!parameters.skipDownload()) { new ArtifactDownloadTask( parameters.getSessionId(), simulatorProperties, outputDirectory, componentRegistry).run(); if (parameters.getAfterCompletionFile() != null) { echoLocal("Executing after-completion script: " + parameters.getAfterCompletionFile()); bash.execute(parameters.getAfterCompletionFile() + " " + outputDirectory.getAbsolutePath()); echoLocal("Finished after-completion script"); } } OperationTypeCounter.printStatistics(); failureCollector.logFailureInfo(); }