DefaultPartBodyStreamStorageFactory implements PartBodyStreamStorageFactory { @Override public StreamStorage newStreamStorageForPartBody(Map<String, List<String>> partHeaders, int partIndex) { return FileStreamStorage.deferred(getTempFile(partIndex), getThreshold(partHeaders)).deleteFilesOnClose().deleteFilesOnDispose(); } DefaultPartBodyStreamStorageFactory(final String tempFolderPath, final int maxSizeThreshold);  DefaultPartBodyStreamStorageFactory(final String tempFolderPath);  DefaultPartBodyStreamStorageFactory(int maxSizeThreshold);  DefaultPartBodyStreamStorageFactory(); @Override StreamStorage newStreamStorageForPartBody(Map<String, List<String>> partHeaders, int partIndex); static final int DEFAULT_MAX_THRESHOLD; }
@Test public void testNewPartIOStreams() throws IOException { DefaultPartBodyStreamStorageFactory defaultPartIOStreamsFactory = new DefaultPartBodyStreamStorageFactory(tempFolder.newFolder("testGetOutputStream").getAbsolutePath()); StreamStorage streamStorage = defaultPartIOStreamsFactory.newStreamStorageForPartBody(new HashMap<String, List<String>>(), 1); assertNotNull(streamStorage); assertTrue(streamStorage instanceof FileStreamStorage); FileStreamStorage FileStreamStorage = (FileStreamStorage) streamStorage; assertTrue(FileStreamStorage.isInMemory()); defaultPartIOStreamsFactory = new DefaultPartBodyStreamStorageFactory(tempFolder.newFolder("testGetOutputStream1").getAbsolutePath(), 100); Map<String, List<String>> headers = new HashMap<String, List<String>>(); headers.put("content-length", Collections.singletonList("99")); streamStorage = defaultPartIOStreamsFactory.newStreamStorageForPartBody(headers, 1); assertNotNull(streamStorage); assertTrue(streamStorage instanceof FileStreamStorage); FileStreamStorage = (FileStreamStorage) streamStorage; assertTrue(FileStreamStorage.isInMemory()); defaultPartIOStreamsFactory = new DefaultPartBodyStreamStorageFactory(tempFolder.newFolder("testGetOutputStream2").getAbsolutePath(), 100); headers = new HashMap<String, List<String>>(); headers.put("content-length", Collections.singletonList("140")); streamStorage = defaultPartIOStreamsFactory.newStreamStorageForPartBody(headers, 1); streamStorage = defaultPartIOStreamsFactory.newStreamStorageForPartBody(headers, 1); assertNotNull(streamStorage); assertTrue(streamStorage instanceof FileStreamStorage); FileStreamStorage = (FileStreamStorage) streamStorage; assertFalse(FileStreamStorage.isInMemory()); }
@Test public void testNewPartIOStreams_error() throws IOException { File folder = tempFolder.newFolder("testGetOutputStream_error"); DefaultPartBodyStreamStorageFactory defaultBodyStreamFactory = new DefaultPartBodyStreamStorageFactory(folder.getAbsolutePath(), 0); assertTrue(folder.delete()); Exception expected = null; try { defaultBodyStreamFactory.newStreamStorageForPartBody(new HashMap<String, List<String>>(), 1); } catch (Exception e) { expected = e; } assertNotNull(expected); }