/** * Gets the input stream of the raw bytes of this body part entity. * * @return the input stream of the body part entity. */ public InputStream getInputStream() { return mimePart.read(); }
/** * Move the contents of the underlying {@link java.io.InputStream} or {@link java.io.File} to the given file. * * @param file destination file. */ public void moveTo(final File file) { mimePart.moveTo(file); // Remember the file where the mime-part object should be stored. Mimepull would not be able to delete it after // it's moved. this.file = file; } }
/** * Get a list of mime part attachments from given mime message. If an exception occurs during parsing the message the parsed * mime parts are closed (any temporary files are deleted). * * @param message mime message to get mime parts from. * @return list of mime part attachments. */ private List<MIMEPart> getMimeParts(final MIMEMessage message) { try { return message.getAttachments(); } catch (final MIMEParsingException obtainPartsError) { LOGGER.log(Level.FINE, LocalizationMessages.PARSING_ERROR(), obtainPartsError); message.close(); // Re-throw the exception. throw obtainPartsError; } }
mediaType = unquoteMediaTypeParameters(mediaType, "boundary"); final MIMEMessage mimeMessage = new MIMEMessage(stream, mediaType.getParameters().get("boundary"), mimeConfig); for (final Header header : mimePart.getAllHeaders()) { bodyPart.getHeaders().add(header.getName(), header.getValue());
private MIMEConfig createMimeConfig(final MultiPartProperties properties) { final MIMEConfig mimeConfig = new MIMEConfig(); // Set values defined by user. mimeConfig.setMemoryThreshold(properties.getBufferThreshold()); final String tempDir = properties.getTempDir(); if (tempDir != null) { mimeConfig.setDir(tempDir); } if (properties.getBufferThreshold() != MultiPartProperties.BUFFER_THRESHOLD_MEMORY_ONLY) { // Validate - this checks whether it's possible to create temp files in currently set temp directory. try { //noinspection ResultOfMethodCallIgnored File.createTempFile("MIME", null, tempDir != null ? new File(tempDir) : null).delete(); } catch (final IOException ioe) { LOGGER.log(Level.WARNING, LocalizationMessages.TEMP_FILE_CANNOT_BE_CREATED(properties.getBufferThreshold()), ioe); } } return mimeConfig; }
/** * Collects the headers for the current part by parsing mesage stream. * * @return headers for the current part */ private InternetHeaders readHeaders() { if (!eof) { fillBuf(); } return new InternetHeaders(new LineInputStream()); }
/** * Creates a new chunk and adds to linked list. * * @param dataHead of the linked list * @param buf MIME part partial data * @return created chunk */ public Chunk createNext(DataHead dataHead, ByteBuffer buf) { return next = new Chunk(data.createNext(dataHead, buf)); } }
/** * Return all the headers * * @return list of Header objects */ public List<? extends Header> getAllHeaders() { getHeaders(); assert headers != null; return headers.getAllHeaders(); }
/** * Cleans up temporary file(s), if any were utilized. */ public void cleanup() { mimePart.close(); if (file != null) { final boolean deleted = file.delete(); if (!deleted) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, LocalizationMessages.TEMP_FILE_NOT_DELETED(file.getAbsolutePath())); } } } }
/** * Return all the values for the specified header. * Returns <code>null</code> if no headers with the * specified name exist. * * @param name header name * @return list of header values, or null if none */ public List<String> getHeader(String name) { getHeaders(); assert headers != null; return headers.getHeader(name); }
/** * Collects the headers for the current part by parsing mesage stream. * * @return headers for the current part */ private InternetHeaders readHeaders() { if (!eof) { fillBuf(); } return new InternetHeaders(new LineInputStream()); }
/** * Creates a new chunk and adds to linked list. * * @param dataHead of the linked list * @param buf MIME part partial data * @return created chunk */ public Chunk createNext(DataHead dataHead, ByteBuffer buf) { return next = new Chunk(data.createNext(dataHead, buf)); } }
/** * Return all the headers * * @return list of Header objects */ public List<? extends Header> getAllHeaders() { getHeaders(); assert headers != null; return headers.getAllHeaders(); }
/** * Collects the headers for the current part by parsing mesage stream. * * @return headers for the current part */ private InternetHeaders readHeaders() { if (!eof) { fillBuf(); } return new InternetHeaders(new LineInputStream()); }
/** * Creates a new chunk and adds to linked list. * * @param dataHead of the linked list * @param buf MIME part partial data * @return created chunk */ public Chunk createNext(DataHead dataHead, ByteBuffer buf) { return next = new Chunk(data.createNext(dataHead, buf)); } }
/** * Return all the headers * * @return list of Header objects */ public List<? extends Header> getAllHeaders() { getHeaders(); assert headers != null; return headers.getAllHeaders(); }
/** * Collects the headers for the current part by parsing mesage stream. * * @return headers for the current part */ private InternetHeaders readHeaders() { if (!eof) { fillBuf(); } return new InternetHeaders(new LineInputStream()); }
/** * Creates a new chunk and adds to linked list. * * @param dataHead of the linked list * @param buf MIME part partial data * @return created chunk */ public Chunk createNext(DataHead dataHead, ByteBuffer buf) { return next = new Chunk(data.createNext(dataHead, buf)); } }
/** * Return all the headers * * @return list of Header objects */ public List<? extends Header> getAllHeaders() { getHeaders(); assert headers != null; return headers.getAllHeaders(); }