List of usage examples for org.apache.commons.io.output NullOutputStream nullOutputStream
public static OutputStream nullOutputStream()
From source file:com.petercho.Encoder.java
private static Checksum checksum(InputStream is, Checksum checksum) throws IOException { InputStream in = new CheckedInputStream(is, checksum); IOUtils.copy(in, new NullOutputStream()); return checksum; }
From source file:mobac.program.tiledatawriter.TileImageJpegDataWriter.java
public static boolean performOpenJDKJpegTest() { try {/* ww w . j a v a 2 s .co m*/ TileImageJpegDataWriter writer = new TileImageJpegDataWriter(0.99d); writer.initialize(); OutputStream out = new NullOutputStream(); BufferedImage image = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB); writer.processImage(image, out); return true; } catch (Exception e) { log.debug("Jpeg test failed", e); return false; } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.legacyExcel.importer.ObjectRelatedPermissionsWorkbookTest.java
/** * Creates an instance of the {@link ObjectRelatedPermissionsWorkbook}. *//*from w ww. j a va 2 s .c om*/ @Before public void setUp() { PrintWriter stream = new PrintWriter(new NullOutputStream()); ProcessingLog userLog = new ProcessingLog(Level.DEBUG, stream); workbook = new ObjectRelatedPermissionsWorkbook(userLog); }
From source file:com.thoughtworks.go.server.service.builders.KillAllChildProcessTaskBuilderTest.java
@Test public void builderReturnedByThisTaskBuilderShouldBeSerializable() throws Exception { KillAllChildProcessTaskBuilder killAllChildProcessTaskBuilder = new KillAllChildProcessTaskBuilder(); Builder builder = killAllChildProcessTaskBuilder.createBuilder(null, null, null, null); new ObjectOutputStream(new NullOutputStream()).writeObject(builder); }
From source file:net.itransformers.idiscover.v2.core.node_discoverers.bgpdiscoverer.BGPMapNetworkDiscoverer.java
protected void startDiscovery(Set<ConnectionDetails> connectionDetailsList) { NetworkDiscoveryResult result = new NetworkDiscoveryResult(null); for (ConnectionDetails connectionDetails : connectionDetailsList) { if (!"javaMRT".equals(connectionDetails.getConnectionType())) { logger.debug("Connection details are not for javaMRTfile"); return; }//from ww w. j a v a 2s . c om String pathToFile = connectionDetails.getParam("pathToFile"); String version = connectionDetails.getParam("version"); String[] args = new String[4]; args[0] = "-f"; args[1] = pathToFile; args[2] = "-o"; String outputFile = ProjectConstants.networkGraphmlFileName; args[3] = outputFile; Map<String, String> params = CmdLineParser.parseCmdLine(args); StringWriter writer = new StringWriter(); String file = null; OutputStream logOutputStream = new NullOutputStream(); if (params.containsKey("-f")) { file = params.get("-f"); } else { logger.info("no file passed"); System.exit(1); } ASContainer ases = new ASContainer(); System.out.println("Start reading MRT file"); File tmpEdgeFile = null; try { tmpEdgeFile = File.createTempFile("test" + "_", ".txt"); System.out.println("Creating edge tmp file: " + tmpEdgeFile.getAbsolutePath()); Writer edgeWriter = new PrintWriter(tmpEdgeFile); Route2GraphmlDumper.dumpToXmlString(new String[] { file }, new PrintWriter(logOutputStream), edgeWriter, ases); edgeWriter.close(); Route2GraphmlDumper.dumpGraphml(ases, writer, tmpEdgeFile); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } finally { tmpEdgeFile.delete(); } NodeDiscoveryResult result1 = new NodeDiscoveryResult(null, null, null); result1.setDiscoveredData("version", version); result1.setDiscoveredData("graphml", writer.toString().getBytes()); result1.setDiscoveredData("discoverer", "javaMRT"); result.addDiscoveredData(file, result1); } fireNetworkDiscoveredEvent(result); }
From source file:net.landora.video.programs.ProgramsAddon.java
public boolean isAvaliable(Program program) { String path = getConfiguredPath(program); if (path == null) { return false; }// w ww. j ava2 s .c o m ArrayList<String> command = new ArrayList<String>(); command.add(path); command.addAll(program.getTestArguments()); ProcessBuilder builder = new ProcessBuilder(command); builder.redirectErrorStream(true); try { Process p = builder.start(); IOUtils.copy(p.getInputStream(), new NullOutputStream()); p.waitFor(); return true; } catch (Exception e) { log.info("Error checking for program: " + program, e); return false; } }
From source file:hudson.plugins.clearcase.cleartool.CTLauncher.java
/** * Run a clearcase command without output to the console, the result of the * command is returned as a String/*from www .j ava 2 s . co m*/ * * @param cmd * the command to launch using the clear tool executable * @param filePath * optional, the path where the command should be launched * @return the result of the command * @throws IOException * @throws InterruptedException */ public String run(ArgumentListBuilder args, FilePath filePath) throws IOException, InterruptedException, ClearToolError { FilePath path = filePath; if (path == null) { path = this.nodeRoot; } ArgumentListBuilder cmd = new ArgumentListBuilder(this.executable); cmd.add(args.toCommandArray()); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); DataOutputStream logStream; if (logFile == null) { logStream = new DataOutputStream(new NullOutputStream()); } else { logStream = new DataOutputStream(new FileOutputStream(logFile, true /*append*/)); } ForkOutputStream forkStream = new ForkOutputStream(outStream, logStream); int code; String cleartoolResult; try { logStream.writeBytes(">>> " + cmd.toStringWithQuote() + "\n"); ProcStarter starter = launcher.launch(); starter.cmds(cmd); starter.envs(this.env); starter.stdout(forkStream); starter.pwd(path); code = launcher.launch(starter).join(); cleartoolResult = outStream.toString(); logStream.writeBytes("\n\n"); // to separate the commands } finally { forkStream.close(); } if (code != 0 || cleartoolResult.contains("cleartool: Error")) { throw new ClearToolError(cmd.toStringWithQuote(), cleartoolResult, code, path); } return cleartoolResult; }
From source file:com.github.neio.filesystem.paths.FilePath.java
@Override public BigInteger sha1Hash() throws NeIOException, FilesystemException { try {/*from w w w . ja va 2s . co m*/ MessageDigest hash = MessageDigest.getInstance("SHA1"); DigestOutputStream digestOutputStream = new DigestOutputStream(new NullOutputStream(), hash); IOUtils.copy(new AutoCloseInputStream(new FileInputStream(new java.io.File(super.path))), digestOutputStream); return new BigInteger(hash.digest()); } catch (NoSuchAlgorithmException e) { throw new NeIOException("Unable calculate hash due to SHA1 Algorithm not being found", e); } catch (FileNotFoundException e) { throw new FilesystemException("File pointed at by this path [" + super.path + "] does not exist", e); } catch (IOException e) { throw new NeIOException(e); } }
From source file:hudson.plugins.script_realm_extended.ExtendedScriptSecurityRealm.java
protected UserDetails authenticate(String username, String password) throws AuthenticationException { try {/* www .j a v a2 s. co m*/ StringWriter out = new StringWriter(); LocalLauncher launcher = new LocalLauncher(new StreamTaskListener(out)); if (launcher.launch().cmds(QuotedStringTokenizer.tokenize(commandLine)).stdout(new NullOutputStream()) .envs("U=" + username, "P=" + password).join() != 0) { throw new BadCredentialsException(out.toString()); } GrantedAuthority[] groups = loadGroups(username); return new User(username, "", true, true, true, true, groups); } catch (InterruptedException e) { throw new AuthenticationServiceException("Interrupted", e); } catch (IOException e) { throw new AuthenticationServiceException("Failed", e); } }
From source file:hudson.plugins.script_realm.ScriptSecurityRealm.java
protected UserDetails authenticate(String username, String password) throws AuthenticationException { try {//from ww w . ja v a 2 s . com StringWriter out = new StringWriter(); LocalLauncher launcher = new LoginScriptLauncher(new StreamTaskListener(out)); Map<String, String> overrides = new HashMap<String, String>(); overrides.put("U", username); overrides.put("P", password); if (isWindows()) { overrides.put("SystemRoot", System.getenv("SystemRoot")); } if (launcher.launch().cmds(QuotedStringTokenizer.tokenize(commandLine)).stdout(new NullOutputStream()) .envs(overrides).join() != 0) { throw new BadCredentialsException(out.toString()); } GrantedAuthority[] groups = loadGroups(username); return new User(username, "", true, true, true, true, groups); } catch (InterruptedException e) { throw new AuthenticationServiceException("Interrupted", e); } catch (IOException e) { throw new AuthenticationServiceException("Failed", e); } }