@Test public void fileNested() throws Exception { waitForWorkspaceChanges(() -> { project.getFolder("/folder").create(true, true, null); project.getFolder("/folder/deep/").create(true, true, null); IFile file = project.getFile("/folder/deep/myFile.ext"); file.create(new NullInputStream(0), true, null); }); URI uri = URI.createPlatformResourceURI("/myProject/folder/deep/myFile.ext", true); IResource iResource = UriUtils.toIResource(uri); assertTrue(iResource instanceof IFile); assertTrue(iResource.exists()); assertEquals("/myProject/folder/deep/myFile.ext", iResource.getFullPath().toString()); }
@Test public void fileSlashesExcess() throws Exception { waitForWorkspaceChanges(() -> { project.getFolder("/folder").create(true, true, null); project.getFolder("/folder/deep/").create(true, true, null); IFile file = project.getFile("/folder/deep/myFile.ext"); file.create(new NullInputStream(0), true, null); }); URI uri = URI.createPlatformResourceURI("////myProject///folder///deep/myFile.ext//", true); IResource iResource = UriUtils.toIResource(uri); assertTrue(iResource instanceof IFile); assertTrue(iResource.exists()); assertEquals("/myProject/folder/deep/myFile.ext", iResource.getFullPath().toString()); }
@Test public void testWriteZeroLength() throws Exception { final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials( System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key") )); final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path room = new SDSDirectoryFeature(session).mkdir( new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus()); final TransferStatus status = new TransferStatus(); final Path test = new Path(room, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final SDSMultipartWriteFeature writer = new SDSMultipartWriteFeature(session); final HttpResponseOutputStream<VersionId> out = writer.write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(status, status).transfer(new NullInputStream(0L), out); final VersionId version = out.getStatus(); assertNotNull(version); assertTrue(new DefaultFindFeature(session).find(test)); new SDSDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
@Override public synchronized int read(final byte[] chunk, final Long offset) throws IOException { final RandomAccessFile file = random(); if(offset < file.length()) { file.seek(offset); if(chunk.length + offset > file.length()) { return file.read(chunk, 0, (int) (file.length() - offset)); } else { return file.read(chunk, 0, chunk.length); } } else { final NullInputStream nullStream = new NullInputStream(length); if(nullStream.available() > 0) { nullStream.skip(offset); return nullStream.read(chunk, 0, chunk.length); } else { return IOUtils.EOF; } } }
@Before public void setUp() throws Exception { releasableInputStream = new ReleasableInputStream(new NullInputStream(2048), () -> wasCalled.set(true)); failedReleasableInputStream = new ReleasableInputStream(new InputStream() { @Override public int read() throws IOException { throw new IOException("Oops"); } @Override public int available() throws IOException { throw new IOException("Oops"); } @Override public synchronized void mark(int readlimit) { throw new RuntimeException("Oops"); } }, () -> wasCalled.set(true)); }
String useFileCollector(FileCollectorAbstract fileCollector) throws Exception { CachingClassLoaderConfiguration classLoaderConfiguration = new CachingClassLoaderConfiguration(); classLoaderConfiguration.setFileCollector(fileCollector); classLoaderConfiguration.setLocalFirst(false); classLoaderConfiguration.setCacheType(CacheType.NoCache, true); classLoaderConfiguration.getCacheConfiguration().setCacheFolder("target"+File.separator +"classLoaderCache"); startup(classLoaderConfiguration); try(at.ac.tuwien.infosys.jcloudscale.classLoader.caching.RemoteClassLoader classLoader = (at.ac.tuwien.infosys.jcloudscale.classLoader.caching.RemoteClassLoader)classLoaderConfiguration.createClassLoader()) { assertSame(at.ac.tuwien.infosys.jcloudscale.classLoader.caching.RemoteClassLoader.class, classLoader.getClass()); InputStream stream = getInputStream(classLoader); return IOUtils.toString(firstNonNull(stream, new NullInputStream(0))); } }
public void testWriteGiantRecord() throws IOException { PrintStream dummyStream = new PrintStream(new NullOutputStream()); ARCWriter arcWriter = new ARCWriter( SERIAL_NO, dummyStream, new File("dummy"), new WriterPoolSettingsData( "", "", -1, false, null, null)); assertNotNull(arcWriter); // Start the record with an arbitrary 14-digit date per RFC2540 long now = System.currentTimeMillis(); long recordLength = org.apache.commons.io.FileUtils.ONE_GB * 3; arcWriter.write("dummy:uri", "application/octet-stream", "0.1.2.3", now, recordLength, new NullInputStream(recordLength)); arcWriter.close(); }
@SuppressWarnings("deprecation") // TEST WITH CORRECT CONFIG AND INVALID INPUT @Test public void testSaveEmailAndNotify_correct_config_invalid_input() throws Exception { // GIVEN I have a server accurately configured (relay domains) ServerConfiguration serverConfiguration = new ServerConfiguration(); MailSaver mailSaver = new MailSaver(serverConfiguration); serverConfiguration.relayDomains("data.org"); MailServerModel mailServerModel = new MailServerModel(); // AND I don't forget to register the mailServerModel mailSaver.addObserver(mailServerModel); // WHEN I sent a mail mailSaver.saveEmailAndNotify(FROM, TO, new NullInputStream(10)); // THEN Assert.assertEquals(1, mailServerModel.getEmailModels().size()); EmailModel emailModel = mailServerModel.getEmailModels().get(0); assertNotNull(emailModel); assertEquals("", emailModel.getSubject()); // }
@Test public void testCloseQuietlyImageInputStreamOpen() { final ImageInputStream in = new MemoryCacheImageInputStream(new NullInputStream(1000)); IOUtils.closeQuietly(in); try { in.close(); fail(); } catch (IOException e) { // This, oddly, the expected behavior of close(). } }
@Test public void fileSlash() throws Exception { waitForWorkspaceChanges(() -> { IFile file = project.getFile("myFile.ext"); file.create(new NullInputStream(0), true, null); }); URI uri = URI.createPlatformResourceURI("/myProject/myFile.ext/", true); IResource iResource = UriUtils.toIResource(uri); assertTrue(iResource instanceof IFile); assertTrue(iResource.exists()); assertEquals("/myProject/myFile.ext", iResource.getFullPath().toString()); }
@Test public void fileDifferentCase() throws Exception { waitForWorkspaceChanges(() -> { IFile file = project.getFile("myFile.ext"); file.create(new NullInputStream(0), true, null); }); URI uri = URI.createPlatformResourceURI("/myProject/MYfILE.ext", true); IResource iResource = UriUtils.toIResource(uri); assertTrue(iResource instanceof IFile); assertFalse(iResource.exists()); assertEquals("/myProject/MYfILE.ext", iResource.getFullPath().toString()); }
@Test public void fragment() throws Exception { waitForWorkspaceChanges(() -> { IFile file = project.getFile("myFile.ext"); file.create(new NullInputStream(0), true, null); }); URI uri = URI.createPlatformResourceURI("/myProject/myFile.ext", true).appendFragment("fragment"); IResource iResource = UriUtils.toIResource(uri); assertTrue(iResource instanceof IFile); assertTrue(iResource.exists()); assertEquals("/myProject/myFile.ext", iResource.getFullPath().toString()); }
@Test public void query() throws Exception { waitForWorkspaceChanges(() -> { IFile file = project.getFile("myFile.ext"); file.create(new NullInputStream(0), true, null); }); URI uri = URI.createPlatformResourceURI("/myProject/myFile.ext", true).appendQuery("query"); IResource iResource = UriUtils.toIResource(uri); assertTrue(iResource instanceof IFile); assertTrue(iResource.exists()); assertEquals("/myProject/myFile.ext", iResource.getFullPath().toString()); }
@Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { if(containerService.isContainer(folder)) { return super.mkdir(folder, region, status); } else { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(folder).compute(new NullInputStream(0L), status)); } return super.mkdir(folder, region, status); } }
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file).compute(new NullInputStream(0L), status)); } status.setTimestamp(System.currentTimeMillis()); final StatusOutputStream<BaseB2Response> out = writer.write(file, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); return new Path(file.getParent(), file.getName(), file.getType(), new PathAttributes(file.attributes()).withVersionId(((B2FileResponse) out.getStatus()).getFileId())); }
@Test public void testDecorate() throws Exception { final NullInputStream n = new NullInputStream(1L); final SwiftSession session = new SwiftSession(new Host(new SwiftProtocol())); assertSame(NullInputStream.class, new SwiftSmallObjectUploadFeature(new SwiftWriteFeature( session, new SwiftRegionService(session))).decorate(n, null).getClass()); }
@Override public Checksum compute(final InputStream in, final TransferStatus status) throws ChecksumException { if(Checksum.NONE == delegate.compute(new NullInputStream(0L), status)) { return Checksum.NONE; } if(null == status.getHeader()) { // Write header to be reused in writer final Cryptor cryptor = cryptomator.getCryptor(); final FileHeader header = cryptor.fileHeaderCryptor().create(); status.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header)); } // Make nonces reusable in case we need to compute a checksum status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(status.getLength()))); return this.compute(in, status.getOffset(), status.getHeader(), status.getNonces()); }
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file).compute(new NullInputStream(0L), status)); } new DefaultStreamCloser().close(writer.write(file, status, new DisabledConnectionCallback())); return file; }
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file).compute(new NullInputStream(0L), status)); } status.setLength(0L); final StatusOutputStream<StorageObject> out = writer.write(file, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); return new Path(file.getParent(), file.getName(), file.getType(), new PathAttributes(file.attributes()).withVersionId(((S3Object) out.getStatus()).getVersionId())); }
@Test public void testDecorate() throws Exception { final NullInputStream n = new NullInputStream(1L); final S3Session session = new S3Session(new Host(new S3Protocol())); assertSame(NullInputStream.class, new S3SingleUploadService(session, new S3WriteFeature(session, new S3DisabledMultipartService())).decorate(n, null).getClass()); }
@Test(expected = IOException.class) public void compute() throws Exception { final NullInputStream in = new NullInputStream(0L); new DisabledChecksumCompute().compute(in, new TransferStatus()); assertEquals(-1, in.read()); in.read(); }
@Test public void testComputeEmptyString() throws Exception { assertEquals("d41d8cd98f00b204e9800998ecf8427e", new MD5ChecksumCompute().compute(IOUtils.toInputStream("", Charset.defaultCharset()), new TransferStatus()).hash); assertEquals("d41d8cd98f00b204e9800998ecf8427e", new MD5ChecksumCompute().compute(new NullInputStream(0L), new TransferStatus().length(0)).hash); }
@Test public void testTransferFixedLength() throws Exception { final TransferStatus status = new TransferStatus().length(432768L); new StreamCopier(status, status).withLimit(432768L).transfer(new NullInputStream(432768L), new NullOutputStream()); assertTrue(status.isComplete()); assertEquals(432768L, status.getOffset(), 0L); }
@Test public void testTransferFixedLengthIncomplete() throws Exception { final TransferStatus status = new TransferStatus().length(432768L); new StreamCopier(status, status).withLimit(432767L).transfer(new NullInputStream(432768L), new NullOutputStream()); assertEquals(432767L, status.getOffset(), 0L); assertTrue(status.isComplete()); }
@Test public void testReadNoEndofStream() throws Exception { final TransferStatus status = new TransferStatus().length(432768L); new StreamCopier(status, status).withLimit(432768L).transfer(new NullInputStream(432770L), new NullOutputStream()); assertEquals(432768L, status.getOffset(), 0L); assertTrue(status.isComplete()); }
@Test public void testCompute() throws Exception { assertEquals("0", new CRC32ChecksumCompute().compute(new NullInputStream(0), new TransferStatus()).hash); assertEquals("d202ef8d", new CRC32ChecksumCompute().compute(new NullInputStream(1L), new TransferStatus()).hash); }
@Test public void shouldWriteOutputDirectlyToOutputStream() throws IOException{ OutputEvent evt = OutputEvent.fromBytes("hello".getBytes(),OutputEvent.SUCCESS,"text/plain"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DefaultEventCodec codec = new DefaultEventCodec(new HashMap<>(), new NullInputStream(0),bos); codec.writeEvent(evt); assertThat(new String(bos.toByteArray())).isEqualTo("hello"); }
@Override public InputStream openStream() throws IOException { try { return file.getInputStream(); } catch ( IOException ioe ) { return new NullInputStream( 0 ); } }
/** * Instantiate a bucket response with the JSON response as a string from * the API call. This response is then parsed into the relevant fields. * * @param response The HTTP response object * * @throws B2ApiException if there was an error parsing the response * @throws IOException if there was an error communicating with the API service */ public B2DownloadFileResponse(CloseableHttpResponse response) throws B2ApiException, IOException { if(null != response.getEntity()) { stream = new HttpMethodReleaseInputStream(response); } else { // HEAD responses do not have an entity stream = new NullInputStream(0L); EntityUtils.consume(response.getEntity()); } contentLength = Long.parseLong(response.getFirstHeader(HttpHeaders.CONTENT_LENGTH).getValue()); contentType = response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue(); contentSha1 = response.getFirstHeader(B2ResponseHeaders.HEADER_X_BZ_CONTENT_SHA1).getValue(); fileId = response.getFirstHeader(B2ResponseHeaders.HEADER_X_BZ_FILE_ID).getValue(); fileName = response.getFirstHeader(B2ResponseHeaders.HEADER_X_BZ_FILE_NAME).getValue(); uploadTimestamp = response.getFirstHeader(B2ResponseHeaders.HEADER_X_BZ_UPLOAD_TIMESTAMP).getValue(); for (Header header : response.getAllHeaders()) { String headerName = header.getName(); String headerValue = header.getValue(); String headerNameLowerCase = headerName.toLowerCase(Locale.ENGLISH); if(headerNameLowerCase.startsWith(B2ResponseHeaders.HEADER_X_BZ_INFO_PREFIX.toLowerCase(Locale.ENGLISH))) { fileInfo.put(headerName.substring(B2ResponseHeaders.HEADER_X_BZ_INFO_PREFIX.length()), headerValue); } else { if(!ignoredHeaders.contains(headerNameLowerCase)) { LOGGER.warn("Found a header named '{}' with value '{}', that was not mapped", headerName, headerValue); } } } }
/** * Test Copying file > 2GB - see issue# IO-84 */ @Test(timeout = 1000) public void testCopy_inputStreamToOutputStream_IO84_add1775() throws Exception { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testCopy_inputStreamToOutputStream_IO84_add1775"); long size = ((long)(Integer.MAX_VALUE)) + ((long)(1)); InputStream in = new NullInputStream(size); OutputStream out = new NullOutputStream(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5357,-1); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5359,null,5358,org.apache.commons.io.IOUtils.copy(in, out)); in.close(); in.close(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5360,size); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5362,null,5361,org.apache.commons.io.IOUtils.copyLarge(in, out)); fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
/** * Test Copying file > 2GB - see issue# IO-84 */ public void testCopy_inputStreamToOutputStream_IO84() throws Exception { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testCopy_inputStreamToOutputStream_IO84"); long size = ((long)(Integer.MAX_VALUE)) + ((long)(2)); InputStream in = new NullInputStream(size); OutputStream out = new NullOutputStream(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5357,-1); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5359,null,5358,org.apache.commons.io.IOUtils.copy(in, out)); in.close(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5360,size); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5362,null,5361,org.apache.commons.io.IOUtils.copyLarge(in, out)); fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
/** * Test Copying file > 2GB - see issue# IO-84 */ public void testCopy_inputStreamToOutputStream_IO84_literalMutation6251() throws Exception { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testCopy_inputStreamToOutputStream_IO84_literalMutation6251"); long size = ((long)(Integer.MAX_VALUE)) + ((long)(0)); InputStream in = new NullInputStream(size); OutputStream out = new NullOutputStream(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5357,-1); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5359,null,5358,org.apache.commons.io.IOUtils.copy(in, out)); in.close(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5360,size); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5362,null,5361,org.apache.commons.io.IOUtils.copyLarge(in, out)); fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
/** * Test Copying file > 2GB - see issue# IO-84 */ public void testCopy_inputStreamToOutputStream_IO84_literalMutation6252() throws Exception { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testCopy_inputStreamToOutputStream_IO84_literalMutation6252"); long size = ((long)(Integer.MAX_VALUE)) + ((long)(0)); InputStream in = new NullInputStream(size); OutputStream out = new NullOutputStream(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5357,-1); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5359,null,5358,org.apache.commons.io.IOUtils.copy(in, out)); in.close(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5360,size); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5362,null,5361,org.apache.commons.io.IOUtils.copyLarge(in, out)); fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
/** * Test Copying file > 2GB - see issue# IO-84 */ @Test(timeout = 1000) public void testCopy_inputStreamToOutputStream_IO84_remove1342() throws Exception { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testCopy_inputStreamToOutputStream_IO84_remove1342"); long size = ((long)(Integer.MAX_VALUE)) + ((long)(1)); InputStream in = new NullInputStream(size); OutputStream out = new NullOutputStream(); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5357,-1); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5359,null,5358,org.apache.commons.io.IOUtils.copy(in, out)); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5360,size); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),5362,null,5361,org.apache.commons.io.IOUtils.copyLarge(in, out)); fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
@Override public InputStream getInputStream(ResourceLocation resourceLocation) throws IOException { BufferedInputStream stream = new BufferedInputStream(new NullInputStream(0)); try { File modFolder = new File(Ar_Reference.getDataFolder(), resourceLocation.getResourceDomain()); File targetFile = new File(modFolder, resourceLocation.getResourcePath()); stream = new BufferedInputStream(new FileInputStream(targetFile)); } catch (Exception e) { FMLLog.getLogger().error("Error reading resource " + resourceLocation.toString()); } return stream; }
/** * Returns an input stream that reads from the log file. * It will use a gzip-compressed log file (log.gz) if that exists. * * @return an input stream from the log file, or null if none exists * @throws IOException */ public InputStream getLogInputStream() throws IOException { File logFile = getLogFile(); if (logFile.exists()) { return new FileInputStream(logFile); } File compressedLogFile = new File(logFile.getParentFile(), logFile.getName() + ".gz"); if (compressedLogFile.exists()) { return new GZIPInputStream(new FileInputStream(compressedLogFile)); } return new NullInputStream(0); }
private void addFileToZip(String filePath, ZipArchiveOutputStream outputStream) { try { outputStream.putArchiveEntry(new ZipArchiveEntry(filePath)); IOUtils.copy(new NullInputStream(1), outputStream); outputStream.closeArchiveEntry(); } catch (IOException ex) { throw new RuntimeException(ex); } }
/** * Test method for * {@link de.ppi.fuwesta.spring.mvc.util.RecursivePropertiesPersister#load(java.util.Properties, java.io.InputStream)} * . * * @throws Exception if something goes wrong. */ @Test public void testLoadPropertiesInputStream() throws Exception { // Arrange final Properties inputProps = getInputProps(); final InputStream is = new NullInputStream(10); // Act testee.load(inputProps, is); // Assert verify(propertiesPersister).load(inputProps, is); assertThat(inputProps).containsOnly(getOutputProps()); }
/** * Test method for * {@link de.ppi.fuwesta.spring.mvc.util.RecursivePropertiesPersister#loadFromXml(java.util.Properties, java.io.InputStream)} * . * * @throws Exception if something goes wrong. */ @Test public void testLoadFromXml() throws Exception { // Arrange final Properties inputProps = getInputProps(); final InputStream is = new NullInputStream(10); // Act testee.loadFromXml(inputProps, is); // Assert verify(propertiesPersister).loadFromXml(inputProps, is); assertThat(inputProps).containsOnly(getOutputProps()); }