private File removeFile(final Payload.Part part) throws IOException { final File result = removeFileWithoutConsumingPartBody(part); consumePartBody(part); return result; }
private static File createTempFolder(final File parent, final Logger logger) throws IOException { return createTempFolder(parent, XFER_DIR_PREFIX, logger); }
private File replaceFile(final Payload.Part part) throws IOException { removeFileWithoutConsumingPartBody(part); return extractFile(part, part.getName()); }
File extractedFile = new File(getOutputFileURI(part, outputName)); dirTimestamps.put(extractedFile, lastModified); postExtract(extractedFile); logger.log(Level.FINER, "Extracted transferred entry {0} to {1}", new Object[]{part.getName(), extractedFile.getAbsolutePath()}); reportExtractionSuccess(); return extractedFile; reportExtractionFailure(part.getName(), e); throw new IOException(e.getMessage(), e); } finally {
private File removeFileWithoutConsumingPartBody(final Payload.Part part) throws IOException { final boolean isFine = logger.isLoggable(Level.FINE); File targetFile = new File(getOutputFileURI(part, part.getName())); if (targetFile.exists()) { final boolean isRemovalRecursive = targetFile.isDirectory() && part.isRecursive(); if (isRemovalRecursive ? FileUtils.whack(targetFile) : targetFile.delete()) { if (isFine) { logger.log(Level.FINER, "Deleted {0}{1} as requested", new Object[]{targetFile.getAbsolutePath(), isRemovalRecursive ? " recursively" : ""}); } reportDeletionSuccess(); } else { if (isFine) { logger.log(Level.FINER, "File {0} ({1}) requested for deletion exists but was not able to be deleted", new Object[]{part.getName(), targetFile.getAbsolutePath()}); } reportDeletionFailure(part.getName(), strings.getLocalString("payload.deleteFailedOnFile", "Requested deletion of {0} failed; the file was found but the deletion attempt failed - no reason is available")); } } else { if (isFine) { logger.log(Level.FINER, "File {0} ({1}) requested for deletion does not exist.", new Object[]{part.getName(), targetFile.getAbsolutePath()}); } reportDeletionFailure(part.getName(), new FileNotFoundException(targetFile.getAbsolutePath())); } return targetFile; }
@Override public void useConnection(final HttpURLConnection urlConnection) throws CommandException, IOException { InputStream in = urlConnection.getInputStream(); String responseContentType = urlConnection.getContentType(); Payload.Inbound inboundPayload = PayloadImpl.Inbound.newInstance(responseContentType, in); if (inboundPayload == null) throw new IOException( strings.get("NoPayloadSupport", responseContentType)); PayloadFilesManager downloadedFilesMgr = new PayloadFilesManager.Perm(fileOutputDir, null, logger, new PayloadFilesManager.ActionReportHandler() { @Override public void handleReport(InputStream reportStream) throws Exception { handleResponse(options, reportStream, urlConnection.getResponseCode(), userOut); } }); try { downloadedFilesMgr.processParts(inboundPayload); } catch (CommandException cex) { throw cex; } catch (Exception ex) { throw new CommandException(ex.getMessage(), ex); } } });
private void processReport(final Payload.Part part) throws Exception { if (reportHandler != null) { reportHandler.handleReport(part.getInputStream()); } else { consumePartBody(part); } }
/** * Returns all Files extracted from the Payload, treating each Part as a * separate file. * @param inboundPayload Payload containing file data to be extracted * @parma reportHandler invoked for each ActionReport Part in the payload * @return the Files corresponding to the content of each extracted file * @throws java.io.IOException */ public List<File> processParts( final Payload.Inbound inboundPayload) throws Exception { return new ArrayList<File>(processPartsExtended(inboundPayload).keySet()); }
protected URI getOutputFileURI(Part part, String name) throws IOException { /* * The part name might have path elements using / as the * separator, so figure out the full path for the resulting * file. */ if (name.startsWith("/")) { name = name.substring(1); } URI targetURI = getParentURI(part).resolve(name); return targetURI; }
File parentFile = getTargetDir(); URI parentFileURI = parentFile.toURI();
isReportProcessed = true; postProcessParts(); return result;
File extractedFile = new File(getOutputFileURI(part, outputName)); dirTimestamps.put(extractedFile, lastModified); postExtract(extractedFile); logger.log(Level.FINER, "Extracted transferred entry {0} to {1}", new Object[]{part.getName(), extractedFile.getAbsolutePath()}); reportExtractionSuccess(); return extractedFile; reportExtractionFailure(part.getName(), e); throw new IOException(e.getMessage(), e); } finally {
private File removeFileWithoutConsumingPartBody(final Payload.Part part) throws IOException { final boolean isFine = logger.isLoggable(Level.FINE); File targetFile = new File(getOutputFileURI(part, part.getName())); if (targetFile.exists()) { final boolean isRemovalRecursive = targetFile.isDirectory() && part.isRecursive(); if (isRemovalRecursive ? FileUtils.whack(targetFile) : targetFile.delete()) { if (isFine) { logger.log(Level.FINER, "Deleted {0}{1} as requested", new Object[]{targetFile.getAbsolutePath(), isRemovalRecursive ? " recursively" : ""}); } reportDeletionSuccess(); } else { if (isFine) { logger.log(Level.FINER, "File {0} ({1}) requested for deletion exists but was not able to be deleted", new Object[]{part.getName(), targetFile.getAbsolutePath()}); } reportDeletionFailure(part.getName(), strings.getLocalString("payload.deleteFailedOnFile", "Requested deletion of {0} failed; the file was found but the deletion attempt failed - no reason is available")); } } else { if (isFine) { logger.log(Level.FINER, "File {0} ({1}) requested for deletion does not exist.", new Object[]{part.getName(), targetFile.getAbsolutePath()}); } reportDeletionFailure(part.getName(), new FileNotFoundException(targetFile.getAbsolutePath())); } return targetFile; }
@Override public void useConnection(final HttpURLConnection urlConnection) throws CommandException, IOException { InputStream in = urlConnection.getInputStream(); String responseContentType = urlConnection.getContentType(); Payload.Inbound inboundPayload = PayloadImpl.Inbound.newInstance(responseContentType, in); if (inboundPayload == null) throw new IOException( strings.get("NoPayloadSupport", responseContentType)); PayloadFilesManager downloadedFilesMgr = new PayloadFilesManager.Perm(fileOutputDir, null, logger, new PayloadFilesManager.ActionReportHandler() { @Override public void handleReport(InputStream reportStream) throws Exception { handleResponse(options, reportStream, urlConnection.getResponseCode(), userOut); } }); try { downloadedFilesMgr.processParts(inboundPayload); } catch (CommandException cex) { throw cex; } catch (Exception ex) { throw new CommandException(ex.getMessage(), ex); } } });
private void processReport(final Payload.Part part) throws Exception { if (reportHandler != null) { reportHandler.handleReport(part.getInputStream()); } else { consumePartBody(part); } }
/** * Returns all Files extracted from the Payload, treating each Part as a * separate file. * @param inboundPayload Payload containing file data to be extracted * @parma reportHandler invoked for each ActionReport Part in the payload * @return the Files corresponding to the content of each extracted file * @throws java.io.IOException */ public List<File> processParts( final Payload.Inbound inboundPayload) throws Exception { return new ArrayList<File>(processPartsExtended(inboundPayload).keySet()); }
protected URI getOutputFileURI(Part part, String name) throws IOException { /* * The part name might have path elements using / as the * separator, so figure out the full path for the resulting * file. */ if (name.startsWith("/")) { name = name.substring(1); } URI targetURI = getParentURI(part).resolve(name); return targetURI; }
File parentFile = getTargetDir(); URI parentFileURI = parentFile.toURI();
isReportProcessed = true; postProcessParts(); return result;
File extractedFile = new File(getOutputFileURI(part, outputName)); dirTimestamps.put(extractedFile, lastModified); postExtract(extractedFile); logger.log(Level.FINER, "Extracted transferred entry {0} to {1}", new Object[]{part.getName(), extractedFile.getAbsolutePath()}); reportExtractionSuccess(); return extractedFile; reportExtractionFailure(part.getName(), e); throw new IOException(e.getMessage(), e); } finally {