List of usage examples for org.apache.commons.io.output NullOutputStream nullOutputStream
public static OutputStream nullOutputStream()
From source file:gate.jape.functest.TestJape.java
/** * This test sets up a JAPE transducer based on a grammar * (RhsError2.jape) that will throw a compiler error. * The test succeeds so long as we get that exception. *//*w ww. ja va2 s. c o m*/ public void disabled_testRhsErrorMessages2() { PrintStream sysout = System.out; System.setOut(new PrintStream(new NullOutputStream())); // run a JAPE batch on the faulty grammar try { Document doc = Factory.newDocument("This is a Small Document."); FeatureMap features = Factory.newFeatureMap(); features.put("orth", "upperInitial"); doc.getAnnotations().add(new Long(0), new Long(8), "Token", features); doTest(doc, "tests/RhsError2.jape", null, null); fail("Bad JAPE grammar (2) didn't throw an exception"); } catch (Exception e) { // success } finally { System.setOut(sysout); } }
From source file:com.cyberway.issue.io.arc.ARCWriterTest.java
public void testWriteGiantRecord() throws IOException { File[] files = { getTmpDir() }; PrintStream dummyStream = new PrintStream(new NullOutputStream()); ARCWriter arcWriter = new ARCWriter(SERIAL_NO, dummyStream, new File("dummy"), false, null, null); assertNotNull(arcWriter);/*from w ww .j a va2s .c o m*/ // 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(); }
From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelAttributesImportServiceImplValuesTest.java
/** * Test method for {@link de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelAttributesImportServiceImpl#importAttributes(java.io.InputStream, java.io.PrintWriter)}. * @throws IOException if the test Excel file will be not found *///from w w w . j av a2 s .c o m @Test public void testImportAttributesEnumValuesUpdate() throws IOException { AttributeTypeGroup atg = testDataHelper.createAttributeTypeGroup("testATG", "", Boolean.TRUE); EnumAT at = testDataHelper.createEnumAttributeType("Test", "", Boolean.FALSE, atg); EnumAV av = testDataHelper.createEnumAV("testValue", "old Description", at); PrintWriter logWriter = new PrintWriter(new NullOutputStream()); Resource excel = new ClassPathResource(EXCEL_TEST_FILES + "enumAttributesValuesUpdateTest.xls"); excelAttributesImportService.importAttributes(excel.getInputStream(), logWriter); commit(); beginTransaction(); List<EnumAV> attributeValues = at.getSortedAttributeValues(); assertEquals(1, attributeValues.size()); assertEquals(av, attributeValues.get(0)); assertEquals("new Description", av.getDescription()); }
From source file:io.milton.cloud.server.apps.calendar.CalendarManager.java
private void updateCtag(Calendar sourceCal) { OutputStream nulOut = new NullOutputStream(); CheckedOutputStream cout = new CheckedOutputStream(nulOut, new Adler32()); appendLine(sourceCal.getColor(), cout); if (sourceCal.getEvents() != null) { for (CalEvent r : sourceCal.getEvents()) { String name = r.getName(); String line = HashCalc.getInstance().toHashableText(name, r.getCtag() + "", ""); appendLine(line, cout);/* w w w .j a v a2 s. c o m*/ } } Checksum check = cout.getChecksum(); long crc = check.getValue(); sourceCal.setCtag(crc); }
From source file:hudson.FilePathTest.java
@Issue("JENKINS-4039") @Test//from w w w . java2s . c om public void archiveBug() throws Exception { FilePath d = new FilePath(channels.french, temp.getRoot().getPath()); d.child("test").touch(0); d.zip(new NullOutputStream()); d.zip(new NullOutputStream(), "**/*"); }
From source file:de.blizzy.backup.check.CheckRun.java
private FileCheckResult checkFile(String backupPath, String checksum, long length, Compression compression) throws IOException { File backupFile = Utils.toBackupFile(backupPath, outputFolder); if (backupFile.isFile()) { InputStream in = null;/*from w ww . ja v a2s . com*/ OutputStream out = null; try { InputStream fileIn = new BufferedInputStream(new FileInputStream(backupFile)); InputStream interceptIn = fileIn; for (IStorageInterceptor interceptor : storageInterceptors) { interceptIn = interceptor.interceptInputStream(interceptIn, length); } InputStream compressIn = compression.getInputStream(interceptIn); LengthOutputStream lengthOut = new LengthOutputStream(new NullOutputStream()); MessageDigest digest = MessageDigest.getInstance("SHA-256"); //$NON-NLS-1$ out = new DigestOutputStream(lengthOut, digest); MessageDigest md5Digest = null; if (checksum.length() != SHA256_LENGTH) { md5Digest = MessageDigest.getInstance("MD5"); //$NON-NLS-1$ out = new DigestOutputStream(out, md5Digest); } in = compressIn; IOUtils.copy(in, out); out.flush(); String fileChecksum = Hex.encodeHexString(digest.digest()); String fileChecksumMD5 = (md5Digest != null) ? Hex.encodeHexString(md5Digest.digest()) : null; long fileLength = lengthOut.getLength(); boolean ok = (fileLength == length) && checksum.equals((checksum.length() == SHA256_LENGTH) ? fileChecksum : fileChecksumMD5); return new FileCheckResult(ok, fileChecksum); } catch (GeneralSecurityException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } } return FileCheckResult.BROKEN; }
From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelAttributesImportServiceImplTest.java
/** * Test method for {@link de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelAttributesImportServiceImpl#importAttributes(java.io.InputStream, java.io.PrintWriter)}. * @throws IOException if the test Excel file will be not found *//* w ww . java 2 s. c om*/ @Test public void testImportAttributesDate() throws IOException { PrintWriter logWriter = new PrintWriter(new NullOutputStream()); Resource excel = new ClassPathResource(EXCEL_TEST_FILES + "dateAttributesTest.xls"); excelAttributesImportService.importAttributes(excel.getInputStream(), logWriter); commit(); beginTransaction(); DateAT dateAt1 = (DateAT) attributeTypeService.getAttributeTypeByName("DateAt1"); assertNotNull(dateAt1); assertEquals("DateAt1 description", dateAt1.getDescription()); assertTrue(dateAt1.isMandatory()); DateAT dateAt2 = (DateAT) attributeTypeService.getAttributeTypeByName("DateAt2"); assertNotNull(dateAt2); assertEquals("DateAt2 description", dateAt2.getDescription()); assertFalse(dateAt2.isMandatory()); }
From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelAttributesImportServiceImplValuesTest.java
/** * Test method for {@link de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelAttributesImportServiceImpl#importAttributes(java.io.InputStream, java.io.PrintWriter)}. * @throws IOException if the test Excel file will be not found *///from w ww. j a v a2 s . co m @Test public void testImportAttributesEnumValuesRename() throws IOException { AttributeTypeGroup atg = testDataHelper.createAttributeTypeGroup("testATG", "", Boolean.TRUE); EnumAT at = testDataHelper.createEnumAttributeType("Test", "", Boolean.FALSE, atg); EnumAV av = testDataHelper.createEnumAV("testValue", "old Description", at); PrintWriter logWriter = new PrintWriter(new NullOutputStream()); Resource excel = new ClassPathResource(EXCEL_TEST_FILES + "enumAttributesValuesRenameTest.xls"); excelAttributesImportService.importAttributes(excel.getInputStream(), logWriter); commit(); beginTransaction(); List<EnumAV> attributeValues = at.getSortedAttributeValues(); assertEquals(1, attributeValues.size()); assertEquals(av, attributeValues.get(0)); assertEquals("value", av.getName()); assertEquals("new Description", av.getDescription()); }
From source file:com.alexholmes.hdfsslurper.WorkerThread.java
private long hdfsFileCRC32(Path path) throws IOException { InputStream in = null;/*from w w w .j av a 2s . c o m*/ CRC32 crc = new CRC32(); try { InputStream is = new BufferedInputStream(path.getFileSystem(config.getConfig()).open(path)); if (config.getCodec() != null) { is = config.getCodec().createInputStream(is); } in = new CheckedInputStream(is, crc); org.apache.commons.io.IOUtils.copy(in, new NullOutputStream()); } finally { org.apache.commons.io.IOUtils.closeQuietly(in); } return crc.getValue(); }
From source file:com.norconex.commons.lang.io.CachedInputStream.java
/** * If not already fully cached, forces the inner input stream to be * fully cached.// w w w .j av a2 s . com * @throws IOException could not enforce full caching */ public void enforceFullCaching() throws IOException { if (firstRead) { IOUtils.copy(this, new NullOutputStream()); } }