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; }
/** * Returns the configuration object. Once this is called, you cannot * change the configuration. * * @return */ @ManagedAttribute public MIMEConfig getConfig() { if (config == null) { config = new MIMEConfig(); config.setDir(dir); config.setParseEagerly(parseEagerly); config.setMemoryThreshold(memoryThreshold); config.validate(); } return config; }
if (!config.isOnlyMemory() && dataHead.inMemory >= config.memoryThreshold) { try { String prefix = config.getTempFilePrefix(); String suffix = config.getTempFileSuffix(); File dir = config.getTempDir(); File tempFile = (dir == null) ? File.createTempFile(prefix, suffix)
/** * @see MIMEMessage(InputStream, String, MIMEConfig) */ public MIMEMessage(InputStream in, String boundary) { this(in, boundary, new MIMEConfig()); }
mimeConfig = new MIMEConfig(); mimeConfig.setMemoryThreshold(-1L); // GAE FIX
private MIMEConfig(boolean parseEagerly, int chunkSize, long inMemoryThreshold, String dir, String prefix, String suffix) { this.parseEagerly = parseEagerly; this.chunkSize = chunkSize; this.memoryThreshold = inMemoryThreshold; this.prefix = prefix; this.suffix = suffix; setDir(dir); }
/** * Validates if it can create temporary files. Otherwise, it stores * attachment contents in memory. */ public void validate() { if (!isOnlyMemory()) { try { File tempFile = (tempDir == null) ? File.createTempFile(prefix, suffix) : File.createTempFile(prefix, suffix, tempDir); tempFile.delete(); } catch(Exception ioe) { memoryThreshold = -1L; // whole attachment will be in-memory } } }
/** * Creates a MIME message from the content's stream. The content stream * is closed when EOF is reached. * * @param in MIME message stream * @param boundary the separator for parts(pass it without --) * @param config various configuration parameters */ public MIMEMessage(InputStream in, String boundary, MIMEConfig config) { this.in = in; this.config = config; MIMEParser parser = new MIMEParser(in, boundary, config); it = parser.iterator(); partsList = new ArrayList<MIMEPart>(); partsMap = new HashMap<String, MIMEPart>(); if (config.isParseEagerly()) { parseAll(); } }
/** * Returns the configuration object. Once this is called, you cannot * change the configuration. * * @return */ @ManagedAttribute public MIMEConfig getConfig() { if (config == null) { config = new MIMEConfig(); config.setDir(dir); config.setParseEagerly(parseEagerly); config.setMemoryThreshold(memoryThreshold); config.validate(); } return config; }
if (!config.isOnlyMemory() && dataHead.inMemory >= config.memoryThreshold) { try { String prefix = config.getTempFilePrefix(); String suffix = config.getTempFileSuffix(); File tempFile = TempFiles.createTempFile(prefix, suffix, config.getTempDir());
/** * @see #MIMEMessage(InputStream, String, MIMEConfig) * * @param in MIME message stream * @param boundary the separator for parts(pass it without --) */ public MIMEMessage(InputStream in, String boundary) { this(in, boundary, new MIMEConfig()); }
private MIMEConfig(boolean parseEagerly, int chunkSize, long inMemoryThreshold, String dir, String prefix, String suffix) { this.parseEagerly = parseEagerly; this.chunkSize = chunkSize; this.memoryThreshold = inMemoryThreshold; this.prefix = prefix; this.suffix = suffix; setDir(dir); }
/** * Validates if it can create temporary files. Otherwise, it stores * attachment contents in memory. */ public void validate() { if (!isOnlyMemory()) { try { File tempFile = (tempDir == null) ? File.createTempFile(prefix, suffix) : File.createTempFile(prefix, suffix, tempDir); boolean deleted = tempFile.delete(); if (!deleted) { if (LOGGER.isLoggable(Level.INFO)) { LOGGER.log(Level.INFO, "File {0} was not deleted", tempFile.getAbsolutePath()); } } } catch(RuntimeException e) { memoryThreshold = -1L; // whole attachment will be in-memory } catch(Exception e) { memoryThreshold = -1L; // whole attachment will be in-memory } } }
/** * Creates a MIME message from the content's stream. The content stream * is closed when EOF is reached. * * @param in MIME message stream * @param boundary the separator for parts(pass it without --) * @param config various configuration parameters */ public MIMEMessage(InputStream in, String boundary, MIMEConfig config) { this.in = in; this.config = config; MIMEParser parser = new MIMEParser(in, boundary, config); it = parser.iterator(); if (config.isParseEagerly()) { parseAll(); } }
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; }
/** * Returns the configuration object. Once this is called, you cannot * change the configuration. * * @return */ @ManagedAttribute public MIMEConfig getConfig() { if (config == null) { config = new MIMEConfig(); config.setDir(dir); config.setParseEagerly(parseEagerly); config.setMemoryThreshold(memoryThreshold); config.validate(); } return config; }
if (!config.isOnlyMemory() && dataHead.inMemory >= config.memoryThreshold) { try { String prefix = config.getTempFilePrefix(); String suffix = config.getTempFileSuffix(); File tempFile = TempFiles.createTempFile(prefix, suffix, config.getTempDir());
/** * @see #MIMEMessage(InputStream, String, MIMEConfig) * * @param in MIME message stream * @param boundary the separator for parts(pass it without --) */ public MIMEMessage(InputStream in, String boundary) { this(in, boundary, new MIMEConfig()); }
private MIMEConfig(boolean parseEagerly, int chunkSize, long inMemoryThreshold, String dir, String prefix, String suffix) { this.parseEagerly = parseEagerly; this.chunkSize = chunkSize; this.memoryThreshold = inMemoryThreshold; this.prefix = prefix; this.suffix = suffix; setDir(dir); }
/** * Validates if it can create temporary files. Otherwise, it stores * attachment contents in memory. */ public void validate() { if (!isOnlyMemory()) { try { File tempFile = (tempDir == null) ? File.createTempFile(prefix, suffix) : File.createTempFile(prefix, suffix, tempDir); boolean deleted = tempFile.delete(); if (!deleted) { if (LOGGER.isLoggable(Level.INFO)) { LOGGER.log(Level.INFO, "File {0} was not deleted", tempFile.getAbsolutePath()); } } } catch(RuntimeException e) { memoryThreshold = -1L; // whole attachment will be in-memory } catch(Exception e) { memoryThreshold = -1L; // whole attachment will be in-memory } } }