@Override public ReadableByteChannel getChannel() throws IOException { return getWrappedRepresentation().getChannel(); }
/** * 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. * * TODO: move this to IOUtils. */ public static File handleBinUpload(String fileName, File directory, boolean deleteDirectoryContent, Request request) throws IOException { final File newFile = new File(directory, fileName); if (deleteDirectoryContent && newFile.exists()) { FileUtils.cleanDirectory(directory); } final ReadableByteChannel source =request.getEntity().getChannel(); final FileChannel outputChannel = IOUtils.getOuputChannel(newFile); IOUtils.copyChannel(1024*1024, source,outputChannel ); IOUtils.closeQuietly(source); IOUtils.closeQuietly(outputChannel); return newFile; }