List of usage examples for org.apache.commons.io.output NullOutputStream nullOutputStream
public static OutputStream nullOutputStream()
From source file:com.thoughtworks.go.agent.launcher.ServerBinaryDownloader.java
private static boolean checksOut(File file, String expectedSignature) { FileInputStream input = null; try {// w w w.j a v a 2 s. c om try { input = new FileInputStream(file); FileDigester fileDigester = new FileDigester(input, new NullOutputStream()); fileDigester.copy(); return expectedSignature.equals(fileDigester.md5()); } finally { if (input != null) { input.close(); } } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:ch.cyberduck.core.PathTest.java
@Test public void testTransferInterrupt() throws Exception { final Path p = new NullPath("/t", Path.FILE_TYPE); final TransferStatus status = new TransferStatus(); final CyclicBarrier lock = new CyclicBarrier(2); final CyclicBarrier exit = new CyclicBarrier(2); status.setLength(432768L);/*from w ww . j ava2s. com*/ new Thread(new Runnable() { @Override public void run() { try { p.transfer(new NullInputStream(status.getLength()), new NullOutputStream(), new StreamListener() { @Override public void bytesSent(long bytes) { // } @Override public void bytesReceived(long bytes) { try { lock.await(); exit.await(); } catch (InterruptedException e) { fail(e.getMessage()); } catch (BrokenBarrierException e) { fail(e.getMessage()); } } }, -1, status); } catch (IOException e) { assertTrue(e instanceof ConnectionCanceledException); } } }).start(); lock.await(); status.setCanceled(); exit.await(); assertFalse(status.isComplete()); assertTrue(status.isCanceled()); assertEquals(32768L, status.getCurrent()); }
From source file:fr.efl.saxon.basex.BaseXQueryTest.java
@Test public void testXsl() { Configuration config = new Configuration(); config.registerExtensionFunction(new BaseXQuery()); Processor proc = new Processor(config); XsltCompiler compiler = proc.newXsltCompiler(); try {/*from w w w . ja v a2 s. c o m*/ InputStream is = new FileInputStream( new File(new File(System.getProperty("user.dir")), "src/test/resources/test1.xsl")); if (is == null) { fail("Impossible de charger la XSL"); } XsltTransformer t = compiler.compile(new StreamSource(is)).load(); t.setDestination(proc.newSerializer(new NullOutputStream())); t.setInitialContextNode(proc.newDocumentBuilder().build(new StreamSource(new FileInputStream( new File(new File(System.getProperty("user.dir")), "src/test/resources/test1.xsl"))))); t.transform(); } catch (SaxonApiException | FileNotFoundException ex) { ex.printStackTrace(System.err); fail(ex.getMessage()); } }
From source file:com.cloudbees.mtslaves.client.RemoteReference.java
protected void drain(HttpURLConnection con) throws IOException { if (con.getResponseCode() >= 500) { String error = IOUtils.toString(con.getErrorStream()); con.getErrorStream().close();/*from w ww . j a va 2s. c om*/ throw new IOException("Error received:" + con.getResponseCode() + "\n" + error); } else { IOUtils.copy(con.getInputStream(), new NullOutputStream()); con.getInputStream().close(); } }
From source file:com.github.vatbub.tictactoe.Board.java
public void doTurn(Move move, boolean ignoreAI) { lastMove = move;/* w ww . j a v a2s .com*/ if (getPlayerAt(move.getRow(), move.getColumn()) != null) { throw new IllegalStateException("Cell is already taken by a player"); } this.setPlayerAt(move.getRow(), move.getColumn(), getCurrentPlayer()); if (getOpponent(getCurrentPlayer()).getPlayerMode().equals(PlayerMode.internetHuman) && !ignoreAI) { KryoGameConnections.sendMove(move); } WinnerInfo winnerInfo = getWinner(move.getRow(), move.getColumn()); if (winnerInfo.winningPlayer != null) { if (getGameEndCallback() != null) { getGameEndCallback().run(winnerInfo); } return; } currentPlayerProperty().set(getOpponent(getCurrentPlayer())); if (getCurrentPlayer().getPlayerMode().equals(PlayerMode.ai) && !ignoreAI) { final Board thisCopy = this; Thread aiWaitThread = new Thread(() -> { PrintStream nullPrintStream = new PrintStream(new NullOutputStream()); while (Main.currentMainWindowInstance.isBlockedForInput()) { // wait nullPrintStream.println("Waiting..."); } try { Thread.sleep(500); } catch (InterruptedException e) { FOKLogger.log(Board.class.getName(), Level.SEVERE, "An error occurred", e); } getCurrentPlayer().doAiTurn(thisCopy); Main.currentMainWindowInstance.updateCurrentPlayerLabel(); Main.currentMainWindowInstance.renderRows(); }); aiWaitThread.setName("aiWaitThread"); aiWaitThread.start(); } }
From source file:com.github.chenxiaolong.dualbootpatcher.switcher.MbtoolTaskOutputFragment.java
@Override public void onStart() { super.onStart(); // Create terminal mSession = new TermSession(); // We don't care about any input because this is kind of a "dumb" terminal output, not // a proper interactive one mSession.setTermOut(new NullOutputStream()); mOS = new PipedOutputStream(); try {//www. j a v a 2 s . c o m mSession.setTermIn(new PipedInputStream(mOS)); } catch (IOException e) { throw new IllegalStateException("Failed to set terminal input stream to pipe", e); } mEmulatorView.attachSession(mSession); // Start and bind to the service Intent intent = new Intent(getActivity(), SwitcherService.class); getActivity().bindService(intent, this, Context.BIND_AUTO_CREATE); getActivity().startService(intent); }
From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelImportServiceAttributesIntegrationTest.java
@Before public void setUp() { super.setUp(); UserContext.setCurrentUserContext(testDataHelper.createUserContext()); PrintWriter logWriter = new PrintWriter(new NullOutputStream()); ProcessingLog userLog = new ProcessingLog(Level.DEBUG, logWriter); new LandscapeDataWorkbook(userLog); }
From source file:com.github.vatbub.tictactoe.view.AnimationThreadPoolExecutor.java
private Runnable createEffectiveWaitingTask(Runnable task) { return () -> { // PrintStreams magically don't make the wait loop hang PrintStream nullStream = new PrintStream(new NullOutputStream()); while (isBlocked()) { nullStream.println("Waiting..."); }//w ww. ja v a2 s. c o m // run Platform.runLater(task); }; }
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 *//*ww w. j a va2 s .c o m*/ @Test public void testImportAttributesEnumValuesAdd() 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 + "enumAttributesValuesTest.xls"); excelAttributesImportService.importAttributes(excel.getInputStream(), logWriter); commit(); beginTransaction(); List<EnumAV> attributeValues = at.getSortedAttributeValues(); assertEquals(3, attributeValues.size()); assertEquals(av, attributeValues.get(0)); EnumAV val1 = attributeValues.get(1); assertEquals("val1", val1.getName()); assertEquals("description1", val1.getDescription()); EnumAV val2 = attributeValues.get(2); assertEquals("val2", val2.getName()); assertEquals("description3", val2.getDescription()); }
From source file:com.cognifide.qa.bb.logging.reporter.SimpleReporter.java
private void setStream() { try {//from ww w .j a v a 2 s . c o m stream = new PrintStream(fileCreator.getReportFile("txt", getReportStartingDate()), StandardCharsets.UTF_8.name()); } catch (IOException e) { LOG.error("Can't create simple reporter file", e); try { stream = new PrintStream(new NullOutputStream(), false, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e2) { LOG.error("UTF-8 is not supported", e2); } } }