/** * Creates and returns a temporary file that will automatically be * deleted when the {@link #close()} method is called. * * @return Created temporary file that'll be deleted after closing * @throws IOException * @see #createTempFile() */ public File createTemporaryFile() throws IOException { return createTempFile().toFile(); }
/** * for testing purposes; this method write the histogram vector to a file. * * @param histogram * @throws IOException */ private void writeHisto(final float[] histogram) throws IOException { Path histPath = new TemporaryResources().createTempFile(); try (Writer writer = Files.newBufferedWriter(histPath, UTF_8)) { for (float bin : histogram) { writer.write(String.valueOf(bin) + "\t"); // writer.write(i + "\t"); } writer.write("\r\n"); } }
public Path getPath() throws IOException { if (path == null) { if (position > 0) { throw new IOException("Stream is already being read"); } else { // Spool the entire stream into a temporary file path = tmp.createTempFile(); Files.copy(in, path, REPLACE_EXISTING); // Create a new input stream and make sure it'll get closed InputStream newStream = Files.newInputStream(path); tmp.addResource(newStream); // Replace the spooled stream with the new stream in a way // that still ends up closing the old stream if or when the // close() method is called. The closing of the new stream // is already being handled as noted above. final InputStream oldStream = in; in = new BufferedInputStream(newStream) { @Override public void close() throws IOException { oldStream.close(); } }; length = Files.size(path); } } return path; }
@Test public void testFileDeletion() throws IOException { Path tempFile; try (TemporaryResources tempResources = new TemporaryResources()) { tempFile = tempResources.createTempFile(); assertTrue("Temp file should exist while TempResources is used", Files.exists(tempFile)); } assertTrue("Temp file should not exist after TempResources is closed", Files.notExists(tempFile)); }
/** * Creates and returns a temporary file that will automatically be * deleted when the {@link #close()} method is called. * * @return Created temporary file that'll be deleted after closing * @throws IOException * @see #createTempFile() */ public File createTemporaryFile() throws IOException { return createTempFile().toFile(); }
/** * Creates and returns a temporary file that will automatically be * deleted when the {@link #close()} method is called. * * @return Created temporary file that'll be deleted after closing * @throws IOException * @see #createTempFile() */ public File createTemporaryFile() throws IOException { return createTempFile().toFile(); }
Path tmpFile = tmp.createTempFile(); try (OutputStream os = Files.newOutputStream(tmpFile)) {
/** * for testing purposes; this method write the histogram vector to a file. * * @param histogram * @throws IOException */ private void writeHisto(final float[] histogram) throws IOException { Path histPath = new TemporaryResources().createTempFile(); try (Writer writer = Files.newBufferedWriter(histPath, UTF_8)) { for (float bin : histogram) { writer.write(String.valueOf(bin) + "\t"); // writer.write(i + "\t"); } writer.write("\r\n"); } }
/** * for testing purposes; this method write the histogram vector to a file. * * @param histogram * @throws IOException */ private void writeHisto(final float[] histogram) throws IOException { Path histPath = new TemporaryResources().createTempFile(); try (Writer writer = Files.newBufferedWriter(histPath, UTF_8)) { for (float bin : histogram) { writer.write(String.valueOf(bin) + "\t"); // writer.write(i + "\t"); } writer.write("\r\n"); } }
public Path getPath() throws IOException { if (path == null) { if (position > 0) { throw new IOException("Stream is already being read"); } else { // Spool the entire stream into a temporary file path = tmp.createTempFile(); Files.copy(in, path, REPLACE_EXISTING); // Create a new input stream and make sure it'll get closed InputStream newStream = Files.newInputStream(path); tmp.addResource(newStream); // Replace the spooled stream with the new stream in a way // that still ends up closing the old stream if or when the // close() method is called. The closing of the new stream // is already being handled as noted above. final InputStream oldStream = in; in = new BufferedInputStream(newStream) { @Override public void close() throws IOException { oldStream.close(); } }; length = Files.size(path); } } return path; }
public Path getPath() throws IOException { if (path == null) { if (position > 0) { throw new IOException("Stream is already being read"); } else { // Spool the entire stream into a temporary file path = tmp.createTempFile(); Files.copy(in, path, REPLACE_EXISTING); // Create a new input stream and make sure it'll get closed InputStream newStream = Files.newInputStream(path); tmp.addResource(newStream); // Replace the spooled stream with the new stream in a way // that still ends up closing the old stream if or when the // close() method is called. The closing of the new stream // is already being handled as noted above. final InputStream oldStream = in; in = new BufferedInputStream(newStream) { @Override public void close() throws IOException { oldStream.close(); } }; length = Files.size(path); } } return path; }
try (final TemporaryResources tmp = new TemporaryResources(); final POIFSFileSystem fs = new POIFSFileSystem()) { source = tmp.createTempFile(); saveEntries((DirectoryEntry) container, fs.getRoot());
try { BufferedImage image = renderer.renderImage(pageIndex, 2.0f, config.getOcrImageType()); Path tmpFile = tmp.createTempFile(); try (OutputStream os = Files.newOutputStream(tmpFile)) {
Path tmpFile = tmp.createTempFile(); try (OutputStream os = Files.newOutputStream(tmpFile)) {