+ public void addFileEntry(FileEntry fileEntry) throws IOException {
+ if (fileEntry instanceof DirectFileEntry) {
+ if (payloadFile == null) {
+ try {
+ payloadFile = File.createTempFile("payload", ".dat", (tempDirectory != null) ? new File(tempDirectory) : null);
+ payloadFile.deleteOnExit();
+ } catch (IOException e) {
+ /* ignore. */
+ }
+ }
+ if (payloadFile != null) {
+ InputStream payloadInputStream = ((DirectFileEntry) fileEntry).getDataInputStream();
+ FileOutputStream payloadOutputStream = null;
+ try {
+ payloadOutputStream = new FileOutputStream(payloadFile, true);
+ byte[] buffer = new byte[65536];
+ int read = 0;
+ while ((read = payloadInputStream.read(buffer)) != -1) {
+ payloadOutputStream.write(buffer, 0, read);
+ }
+ payloadOutputStream.flush();
+ fileEntries.add(fileEntry);
+ } catch (IOException ioe1) {
+ payloadFile.delete();
+ throw ioe1;
+ } finally {
+ Closer.close(payloadOutputStream);
+ Closer.close(payloadInputStream);
+ }
+ }
+ } else {
+ fileEntries.add(fileEntry);
+ }