/** * Copy the input file onto the output file using a default buffer size. * * @param sourceFile the {@link File} to copy from. * @param destinationFile the {@link File} to copy to. * @throws IOException in case something bad happens. */ public static void copyFile(File sourceFile, File destinationFile) throws IOException { copyFile(sourceFile, destinationFile, DEFAULT_SIZE); }
/** * Convenience method for subclasses to look up the (URL-decoded)value of * an attribute from the request, ie {@link Request#getAttributes()}. * * @param attribute The name of the attribute to lookup. * * @return The value as a string, or null if the attribute does not exist * or cannot be url-decoded. */ protected String getAttribute(Request request, String attribute) { return RESTUtils.getAttribute(request, attribute); } //@Override
/** * Inflate the provided {@link ZipFile} in the provided output directory. * * @param archive the {@link ZipFile} to inflate. * @param outputDirectory the directory where to inflate the archive. * @param fileName name of the file if present. * @throws IOException in case something bad happens. */ public static void inflate(ZipFile archive, Resource outputDirectory, String fileName) throws IOException { inflate(archive, outputDirectory, fileName, null, null, null, false, false); }
/** * Constructor for a {@link FileCleaner}. * * @param period default time period between two cycles. * @param priority is the priority for the cleaner thread. * @param maxattempts maximum number of time the cleaner thread tries to delete a file. */ public FileCleaner(long period, int priority, int maxattempts) { this.period = period; this.setName("FileCleaner"); this.setPriority(priority); this.setDaemon(true); this.maxAttempts = maxattempts; }
/** * Unzips a zip a file to a specified directory, deleting the zip file after unpacking. * * @param zipFile The zip file. * @param outputDirectory The directory to unpack the contents to. * @throws IOException Any I/O errors that occur. * <p>TODO: move this to IOUtils */ public static void unzipFile( org.geoserver.platform.resource.Resource zipFile, org.geoserver.platform.resource.Resource outputDirectory) throws IOException { unzipFile(zipFile, outputDirectory, null, null, null, null, false); }
/** * 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); }
/** * Reads content from the body of a request and writes it to a file. * * @param fileName The name of the file to write out. * @param directory The directory to write the file to. * @param deleteDirectoryContent Delete directory content if the file already exists. * @param request The request. * @return The file object representing the newly written file. * @throws IOException Any I/O errors that occur. * <p>TODO: move this to IOUtils. */ public static org.geoserver.platform.resource.Resource handleBinUpload( String fileName, org.geoserver.platform.resource.Resource directory, boolean deleteDirectoryContent, HttpServletRequest request) throws IOException { return handleBinUpload(fileName, directory, deleteDirectoryContent, request, null); }
/** * Convert the input from the provided {@link InputStream} into a {@link String}. * * @param inputStream the {@link InputStream} to copy from. * @return a {@link String} that contains the content of the provided {@link InputStream}. * @throws IOException in case something bad happens. */ public static String getStringFromStream(InputStream inputStream) throws IOException { inputNotNull(inputStream); final Reader inReq = new InputStreamReader(inputStream); return getStringFromReader(inReq); }
/** * Delete the specified File. * * @param file the file to delete */ public static void deleteFile(File file) { inputNotNull(file); if (!file.exists() || !file.canRead() || !file.isFile()) throw new IllegalStateException("Source is not in a legal state."); if (file.delete()) return; IOUtils.FILE_CLEANER.addFile(file); }
@Override protected String readInternal(Class<? extends String> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { return IOUtils.getStringFromStream(inputMessage.getBody()); }
/** * Convenience method for subclasses to look up the (URL-decoded) value of a value specified * in the request query string. * * @param key The name of the value to lookup. * * @return The converted value, or <code>null</code> if the value was not specified. */ protected String getQueryStringValue(String key) { return RESTUtils.getQueryStringValue(getRequest(), key); }
/** * Fetch a request attribute as a String, accounting for URL-encoding. * * @param request the Restlet Request object that might contain the attribute * @param name the name of the attribute to retrieve * @return the attribute, URL-decoded, if it exists and is a valid URL-encoded string, or null * otherwise */ public static String getAttribute(HttpServletRequest request, String name) { Object o = request.getAttribute(name); return decode(o); }
/** * Close the specified input <code>FileChannel</code> * * @throws IOException in case something bad happens. */ public static void closeQuietly(Channel channel) throws IOException { inputNotNull(channel); if (channel.isOpen()) channel.close(); }
/** * Constructor for a {@link FileCleaner}. * * @param period default time period between two cycles. * @param priority is the priority for the cleaner thread. * @param maxattempts maximum number of time the cleaner thread tries to delete a file. */ public FileCleaner(long period, int priority, int maxattempts) { this.period = period; this.setName("FileCleaner"); this.setPriority(priority); this.setDaemon(true); this.maxAttempts = maxattempts; }
/** * Convenience method for subclasses to look up the (URL-decoded)value of * an attribute from the request, ie {@link Request#getAttributes()}. * * @param attribute The name of the attribute to lookup. * * @return The value as a string, or null if the attribute does not exist * or cannot be url-decoded. */ protected String getAttribute(String attribute) { return RESTUtils.getAttribute(getRequest(), attribute); }
/** * Inflate the provided {@link ZipFile} in the provided output directory. * * @param archive the {@link ZipFile} to inflate. * @param outputDirectory the directory where to inflate the archive. * @param fileName name of the file if present. * @param external * @throws IOException in case something bad happens. */ public static void inflate( ZipFile archive, Resource outputDirectory, String fileName, boolean external) throws IOException { inflate(archive, outputDirectory, fileName, null, null, null, external, false); }
/** * 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); }
/** * This function gets the stream of the request to copy it into a file. * @deprecated use {@link #handleBinUpload(String, File, Request)}. */ public static File handleBinUpload(String datasetName, String extension, Request request) throws IOException, ConfigurationException { final File dir = GeoserverDataDirectory.findCreateConfigDir("data"); return handleBinUpload( datasetName + "." + extension, dir, request ); }
/** * Copy the input file onto the output file using a default buffer size. * * @param sourceFile the {@link File} to copy from. * @param destinationFile the {@link File} to copy to. * @throws IOException in case something bad happens. */ public static void copyFile(File sourceFile, File destinationFile) throws IOException { copyFile(sourceFile, destinationFile, DEFAULT_SIZE); }
/** * Convenience method for subclasses to look up the (URL-decoded)value of * an attribute from the request, ie {@link Request#getAttributes()}. * * @param attribute THe name of the attribute to lookup. * * @return The value as a string, or null if the attribute does not exist * or cannot be url-decoded. */ protected String getAttribute(String attribute) { return RESTUtils.getAttribute(getRequest(), attribute); }