/** * Copy {@link InputStream} to {@link OutputStream}. * * @param sourceStream {@link InputStream} to copy from. * @param destinationStream {@link OutputStream} to copy to. * @param closeInput quietly close {@link InputStream}. * @param closeOutput quietly close {@link OutputStream} * @throws IOException in case something bad happens. */ public static void copyStream( InputStream sourceStream, OutputStream destinationStream, boolean closeInput, boolean closeOutput) throws IOException { copyStream(sourceStream, destinationStream, DEFAULT_SIZE, closeInput, closeOutput); }
/** * Copy {@link InputStream} to {@link OutputStream}. * * @param sourceStream {@link InputStream} to copy from. * @param destinationStream {@link OutputStream} to copy to. * @param closeInput quietly close {@link InputStream}. * @param closeOutput quietly close {@link OutputStream} * @throws IOException in case something bad happens. */ public static void copyStream(InputStream sourceStream, OutputStream destinationStream, boolean closeInput, boolean closeOutput) throws IOException { copyStream(sourceStream, destinationStream, DEFAULT_SIZE, closeInput, closeOutput); }
final OutputStream out = new BufferedOutputStream(new FileOutputStream(outFile)); IOUtils.copyStream(in, out, true, true);
final InputStream inputStream = fileURL.openStream(); final OutputStream outStream = new FileOutputStream(newFile); IOUtils.copyStream(inputStream, outStream, true, true);
IOUtils.copyStream(inputStream, outStream, true, true);
/** * Simple class implementing a periodic Thread that periodically tries to delete the files that * were provided to him. * * <p>It tries to delete each file at most {@link FileCleaner#maxAttempts} number of times. If * this number is exceeded it simply throws the file away notifying the users with a warning * message. * * @author Simone Giannecchini, GeoSolutions. */ public static final class FileCleaner extends Thread { /** * Maximum number of attempts to delete a given {@link File}. * * <p>If the provided number of attempts is exceeded we simply drop warn the user and we * remove the {@link File} from our list. */ private int maxAttempts = DEF_MAX_ATTEMPTS; /** Period in seconds between two checks. */ private volatile long period = DEFAULT_PERIOD; /** * Asks this {@link FileCleaner} to clean up this file. * * @param fileToDelete {@link File} that we want to permanently delete. */ public void addFile(final File fileToDelete) { // does it exists
/** * Save the image resources in the styles folder * * @param directory Temporary directory containing the image files to save * @param workspaceName Name of the workspace of the style (or null for a global style) * @throws IOException if there was an error saving the image resources */ private void saveImageResources(File directory, String workspaceName) throws IOException { Resource stylesDir = workspaceName == null ? dataDir.getStyles() : dataDir.getStyles(catalog.getWorkspaceByName(workspaceName)); File[] imageFiles = listImageFiles(directory); for (File imageFile : imageFiles) { IOUtils.copyStream( new FileInputStream(imageFile), stylesDir.get(imageFile.getName()).out(), true, true); } }
private Resource readMosaic() throws FactoryException, IOException { // Select the zip file containing the mosaic URL mosaicZip = getClass().getResource("test-data/watertemp2.zip"); Resource zipFile = Files.asResource(URLs.urlToFile(mosaicZip)); // Creation of another zip file which is a copy of the one before Resource newZip = zipFile.parent().get("watertemp2_temp.zip"); // Copy the content of the first zip to the second IOUtils.copyStream(zipFile.in(), newZip.out(), true, true); Resource mosaic = zipFile.parent().get("mosaic"); mosaic.delete(); RESTUtils.unzipFile(newZip, mosaic); return mosaic; }
@Before public void initialise() throws IOException { myRes = getDataDirectory().get("/mydir/myres"); try (OutputStreamWriter os = new OutputStreamWriter(myRes.out())) { os.append(STR_MY_TEST); } try (OutputStreamWriter os = new OutputStreamWriter(getDataDirectory().get("/mydir2/myres.xml").out())) { os.append(STR_MY_TEST); } try (OutputStreamWriter os = new OutputStreamWriter(getDataDirectory().get("/mydir2/myres.json").out())) { os.append(STR_MY_TEST); } try (OutputStreamWriter os = new OutputStreamWriter(getDataDirectory().get("/mydir2/fake.png").out())) { os.append("This is not a real png file."); } try (OutputStreamWriter os = new OutputStreamWriter(getDataDirectory().get("/poëzie/café").out())) { os.append("The content of this file is irrelevant."); } IOUtils.copyStream( getClass().getResourceAsStream("testimage.png"), getDataDirectory().get("/mydir2/imagewithoutextension").out(), true, true); }
Resource newZip = Files.asResource(new File("./target/harvesting2.zip")); IOUtils.copyStream(zipHarvest.openStream(), newZip.out(), true, true); Resource outputDirectory = Files.asResource(new File("./target/harvesting")); RESTUtils.unzipFile(newZip, outputDirectory);