/** * Read and return the entire contents of the supplied {@link InputStream}. This method always closes the stream when finished * reading. * * @param stream the streamed contents; may be null * @return the contents, or an empty string if the supplied stream is null * @throws IOException if there is an error reading the content */ public static String read(InputStream stream) throws IOException { return stream == null ? "" : read(new InputStreamReader(stream)); }
/** * Read and return the entire contents of the supplied {@link InputStream}. This method always closes the stream when finished * reading. * * @param stream the streamed contents; may be null * @param charset character set of the stream data; may not be null * @return the contents, or an empty string if the supplied stream is null * @throws IOException if there is an error reading the content */ public static String read(InputStream stream, String charset) throws IOException { return stream == null ? "" : read(new InputStreamReader(stream, charset)); }
protected String readFile(String classpathResource) { try (InputStream stream = getClass().getClassLoader().getResourceAsStream(classpathResource);) { assertThat(stream).isNotNull(); return IoUtil.read(stream); } catch (IOException e) { fail("Unable to read '" + classpathResource + "'"); } assert false : "should never get here"; return null; }
protected String readFile(String classpathResource) { try (InputStream stream = getClass().getClassLoader().getResourceAsStream(classpathResource);) { assertThat(stream).isNotNull(); return IoUtil.read(stream); } catch (IOException e) { fail("Unable to read '" + classpathResource + "'"); } assert false : "should never get here"; return null; }
/** * Read a classpath resource into a string. * * @param pathOnClasspath the path of the resource on the classpath * @return the string representation */ public static String readResourceAsString(String pathOnClasspath) { try (InputStream stream = readResourceAsStream(pathOnClasspath)) { return IoUtil.read(stream); } catch (IOException e) { Fail.fail("Unable to read '" + pathOnClasspath + "'", e); return null; } }
protected void appendCommand(Path results, Document command) throws IOException { assertThat(command).isNotNull(); assertThat(Files.exists(results)).isTrue(); Array arrayOfDocuments = readResults(results.toFile()); arrayOfDocuments.add(command); try (OutputStream stream = new FileOutputStream(results.toFile())) { ArrayWriter.prettyWriter().write(arrayOfDocuments, stream); } if (Testing.Debug.isEnabled()) { String content = IoUtil.read(results.toFile()); Testing.debug("expected results file '" + results + "' after appending command:"); Testing.debug(content); } }
protected void assertExpectedRecords(Path path, int batchCount, int recordsPerBatch) throws IOException { assertThat(Files.exists(path)).isTrue(); if (Testing.Debug.isEnabled()) { String content = IoUtil.read(path.toFile()); Testing.debug("expected results file '" + path + "':"); Testing.debug(content);
/** * Read and return the entire contents of the supplied {@link InputStream}. This method always closes the stream when finished * reading. * * @param stream the streamed contents; may be null * @return the contents, or an empty string if the supplied stream is null * @throws IOException if there is an error reading the content */ public static String read(InputStream stream) throws IOException { return stream == null ? "" : read(new InputStreamReader(stream)); }
/** * Read and return the entire contents of the supplied {@link InputStream}. This method always closes the stream when finished * reading. * * @param stream the streamed contents; may be null * @param charset character set of the stream data; may not be null * @return the contents, or an empty string if the supplied stream is null * @throws IOException if there is an error reading the content */ public static String read(InputStream stream, String charset) throws IOException { return stream == null ? "" : read(new InputStreamReader(stream, charset)); }
protected String readFile(String classpathResource) { try (InputStream stream = getClass().getClassLoader().getResourceAsStream(classpathResource);) { assertThat(stream).isNotNull(); return IoUtil.read(stream); } catch (IOException e) { fail("Unable to read '" + classpathResource + "'"); } assert false : "should never get here"; return null; }
protected String readFile(String classpathResource) { try (InputStream stream = getClass().getClassLoader().getResourceAsStream(classpathResource);) { assertThat(stream).isNotNull(); return IoUtil.read(stream); } catch (IOException e) { fail("Unable to read '" + classpathResource + "'"); } assert false : "should never get here"; return null; }
protected void appendCommand(Path results, Document command) throws IOException { assertThat(command).isNotNull(); assertThat(Files.exists(results)).isTrue(); Array arrayOfDocuments = readResults(results.toFile()); arrayOfDocuments.add(command); try (OutputStream stream = new FileOutputStream(results.toFile())) { ArrayWriter.prettyWriter().write(arrayOfDocuments, stream); } if (Testing.Debug.isEnabled()) { String content = IoUtil.read(results.toFile()); Testing.debug("expected results file '" + results + "' after appending command:"); Testing.debug(content); } }
protected void assertExpectedRecords(Path path, int batchCount, int recordsPerBatch) throws IOException { assertThat(Files.exists(path)).isTrue(); if (Testing.Debug.isEnabled()) { String content = IoUtil.read(path.toFile()); Testing.debug("expected results file '" + path + "':"); Testing.debug(content);