private static DiskFileItem makePayload(int thresh, String repoPath, String filePath, byte[] data) throws IOException, Exception { // if thresh < written length, delete outputFile after copying to repository temp file // otherwise write the contents to repository temp file File repository = new File(repoPath); DiskFileItem diskFileItem = new DiskFileItem("test", "application/octet-stream", false, "test", 100000, repository, null); File outputFile = new File(filePath); DeferredFileOutputStream dfos = new DeferredFileOutputStream(thresh, outputFile); OutputStream os = (OutputStream) Reflections.getFieldValue(dfos, "memoryOutputStream"); os.write(data); Reflections.getField(ThresholdingOutputStream.class, "written").set(dfos, data.length); Reflections.setFieldValue(diskFileItem, "dfos", dfos); Reflections.setFieldValue(diskFileItem, "sizeThreshold", 0); return diskFileItem; }
/** * Returns an {@link java.io.OutputStream OutputStream} that can be used for storing the * contents of the file. * * @return An {@link java.io.OutputStream OutputStream} that can be used for storing the * contensts of the file. * * @throws IOException * if an error occurs. */ public OutputStream getOutputStream() throws IOException { if (dfos == null) { dfos = new DeferredFileOutputStream(sizeThreshold, new DeferredFileOutputStream.FileFactory() { public File createFile() { return getTempFile(); } }); } return dfos; }
/** * Returns an {@link java.io.OutputStream OutputStream} that can be used for storing the * contents of the file. * * @return An {@link java.io.OutputStream OutputStream} that can be used for storing the * contensts of the file. * * @exception IOException * if an error occurs. */ public OutputStream getOutputStream() throws IOException { if (dfos == null) { File outputFile = getTempFile(); dfos = new DeferredFileOutputStream(sizeThreshold, outputFile); } return dfos; }