List of usage examples for java.io OutputStream OutputStream
OutputStream
From source file:net.chrislongo.hls.Main.java
public static void main(String[] args) { CommandLine commandLine = parseCommandLine(args); String[] commandLineArgs = commandLine.getArgs(); try {/*w w w .j ava2s . c o m*/ String playlistUrl = commandLineArgs[0]; String outFile = null; String key = null; if (commandLine.hasOption(OPT_OUT_FILE)) { outFile = commandLine.getOptionValue(OPT_OUT_FILE); File file = new File(outFile); if (file.exists()) { if (!commandLine.hasOption(OPT_OVERWRITE)) { System.out.printf("File '%s' already exists. Overwrite? [y/N] ", outFile); int ch = System.in.read(); if (!(ch == 'y' || ch == 'Y')) { System.exit(0); } } file.delete(); } } if (commandLine.hasOption(OPT_KEY)) key = commandLine.getOptionValue(OPT_KEY); PlaylistDownloader downloader = new PlaylistDownloader(playlistUrl); if (commandLine.hasOption(OPT_SILENT)) { System.setOut(new PrintStream(new OutputStream() { public void close() { } public void flush() { } public void write(byte[] b) { } public void write(byte[] b, int off, int len) { } public void write(int b) { } })); } downloader.download(outFile, key); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
From source file:android.example.hlsmerge.crypto.Main.java
public static void main(String[] args) { CommandLine commandLine = parseCommandLine(args); String[] commandLineArgs = commandLine.getArgs(); try {//from w w w .j a v a 2s . co m String playlistUrl = commandLineArgs[0]; String outFile = null; String key = null; if (commandLine.hasOption(OPT_OUT_FILE)) { outFile = commandLine.getOptionValue(OPT_OUT_FILE); File file = new File(outFile); if (file.exists()) { if (!commandLine.hasOption(OPT_OVERWRITE)) { System.out.printf("File '%s' already exists. Overwrite? [y/N] ", outFile); int ch = System.in.read(); if (!(ch == 'y' || ch == 'Y')) { System.exit(0); } } file.delete(); } } if (commandLine.hasOption(OPT_KEY)) key = commandLine.getOptionValue(OPT_KEY); PlaylistDownloader downloader = new PlaylistDownloader(playlistUrl, null); if (commandLine.hasOption(OPT_SILENT)) { System.setOut(new PrintStream(new OutputStream() { public void close() { } public void flush() { } public void write(byte[] b) { } public void write(byte[] b, int off, int len) { } public void write(int b) { } })); } downloader.download(outFile, key); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
From source file:net.yash069.hls.Main.java
public static void main(String[] args) { CommandLine commandLine = parseCommandLine(args); String[] commandLineArgs = commandLine.getArgs(); try {/*w ww . j a v a 2s . com*/ String playlistUrl = commandLineArgs[0]; String outFile = null; String key = null; String lplaylist = null; if (commandLine.hasOption(OPT_OUT_FILE)) { outFile = commandLine.getOptionValue(OPT_OUT_FILE); File file = new File(outFile); if (file.exists()) { if (!commandLine.hasOption(OPT_OVERWRITE)) { System.out.printf("File '%s' already exists. Overwrite? [y/N] ", outFile); int ch = System.in.read(); if (!(ch == 'y' || ch == 'Y')) { System.exit(0); } } file.delete(); } } if (commandLine.hasOption(OPT_KEY)) key = commandLine.getOptionValue(OPT_KEY); if (commandLine.hasOption(OPT_PLAYLIST)) lplaylist = commandLine.getOptionValue(OPT_PLAYLIST); PlaylistDownloader downloader = new PlaylistDownloader(playlistUrl, lplaylist); if (commandLine.hasOption(OPT_SILENT)) { System.setOut(new PrintStream(new OutputStream() { public void close() { } public void flush() { } public void write(byte[] b) { } public void write(byte[] b, int off, int len) { } public void write(int b) { } })); } downloader.download(outFile, key); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
From source file:parquet.tools.Main.java
public static void main(String[] args) { Main.out = System.out;// w w w .j a va2 s . c o m Main.err = System.err; System.setOut(new PrintStream(new OutputStream() { @Override public void write(int b) throws IOException { } @Override public void write(byte[] b) throws IOException { } @Override public void write(byte[] b, int off, int len) throws IOException { } @Override public void flush() throws IOException { } @Override public void close() throws IOException { } })); System.setErr(new PrintStream(new OutputStream() { @Override public void write(int b) throws IOException { } @Override public void write(byte[] b) throws IOException { } @Override public void write(byte[] b, int off, int len) throws IOException { } @Override public void flush() throws IOException { } @Override public void close() throws IOException { } })); if (args.length == 0) { die("No command specified", true, null, null); } String name = args[0]; if ("-h".equals(name) || "--help".equals(name)) { showUsage(); System.exit(0); } Command command = Registry.getCommandByName(name); if (command == null) { die("Unknown command: " + name, true, null, null); } boolean debug = false; Options options = mergeOptions(OPTIONS, command.getOptions()); try { String[] cargs = Arrays.copyOfRange(args, 1, args.length); Options opts = mergeOptions(OPTIONS, command.getOptions()); boolean extra = command.supportsExtraArgs(); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(opts == null ? new Options() : opts, cargs, extra); if (cmd.hasOption('h')) { showUsage(name, command); System.exit(0); } if (cmd.hasOption("no-color")) { System.setProperty("DISABLE_COLORS", "true"); } debug = cmd.hasOption("debug"); command.execute(cmd); } catch (ParseException ex) { if (debug) ex.printStackTrace(Main.err); die("Invalid arguments: " + ex.getMessage(), true, name, command); } catch (Throwable th) { if (debug) th.printStackTrace(Main.err); die(th, false, name, command); } }
From source file:org.apache.parquet.tools.Main.java
public static void main(String[] args) { Main.out = System.out;/*from w w w. j ava 2 s .co m*/ Main.err = System.err; PrintStream VoidStream = new PrintStream(new OutputStream() { @Override public void write(int b) throws IOException { } @Override public void write(byte[] b) throws IOException { } @Override public void write(byte[] b, int off, int len) throws IOException { } @Override public void flush() throws IOException { } @Override public void close() throws IOException { } }); System.setOut(VoidStream); System.setErr(VoidStream); if (args.length == 0) { die("No command specified", true, null, null); } String name = args[0]; if ("-h".equals(name) || "--help".equals(name)) { showUsage(); System.exit(0); } Command command = Registry.getCommandByName(name); if (command == null) { die("Unknown command: " + name, true, null, null); } boolean debug = false; try { String[] cargs = Arrays.copyOfRange(args, 1, args.length); Options opts = mergeOptions(OPTIONS, command.getOptions()); boolean extra = command.supportsExtraArgs(); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(opts == null ? new Options() : opts, cargs, extra); if (cmd.hasOption('h')) { showUsage(name, command); System.exit(0); } if (cmd.hasOption("no-color")) { System.setProperty("DISABLE_COLORS", "true"); } debug = cmd.hasOption("debug"); command.execute(cmd); } catch (ParseException ex) { if (debug) ex.printStackTrace(Main.err); die("Invalid arguments: " + ex.getMessage(), true, name, command); } catch (Throwable th) { if (debug) th.printStackTrace(Main.err); die(th, false, name, command); } }
From source file:Main.java
public static OutputStream out(final JTextArea ta) { return new OutputStream() { public void write(int b) throws IOException { ta.append(String.valueOf((char) b)); }//from w w w. j a va 2 s. com }; }
From source file:Main.java
/** * Creates a no-op outputStream./*from w ww . j a va 2 s. c o m*/ */ public static OutputStream nopOuputStream() { return new OutputStream() { @Override public void write(int paramInt) throws IOException { // Do nothing } }; }
From source file:Main.java
public static String parseBeanToXmlStringByJAXB(Object bean, Class clase) throws Exception { JAXBContext jc = JAXBContext.newInstance(clase); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false); JAXBElement<Object> rootElement = new JAXBElement<Object>(new QName(clase.getSimpleName()), clase, bean); OutputStream output = new OutputStream() { private StringBuilder string = new StringBuilder(); public void write(int b) throws IOException { this.string.append((char) b); }/* w w w .j a va 2 s . c om*/ //Netbeans IDE automatically overrides this toString() public String toString() { return this.string.toString(); } }; marshaller.marshal(rootElement, output); return output.toString(); }
From source file:mockit.integration.logging.LoggingIntegrationsTest.java
@BeforeClass public static void redirectSystemOut() { originalErr = System.err;//from ww w .ja v a 2 s .c o m OutputStream testOutput = new OutputStream() { @Override public void write(int b) { fail("Logger wrote output message!"); } }; System.setErr(new PrintStream(testOutput)); }
From source file:Main.java
public static String getResponseInFile(String address, File file) throws IOException { String dataString = ""; InputStream inputStream = null; OutputStream outputStream = null; try {/*w w w. java 2s . c o m*/ URL url = new URL(address); URLConnection connection = url.openConnection(); inputStream = connection.getInputStream(); byte[] data; if (inputStream.available() > BUFFER_SIZE) { data = new byte[BUFFER_SIZE]; } else { data = new byte[inputStream.available()]; } int dataCount; while ((dataCount = inputStream.read(data)) > 0) { outputStream.write(data, 0, dataCount); } OutputStream output = new OutputStream() { private StringBuilder string = new StringBuilder(); @Override public void write(int b) throws IOException { this.string.append((char) b); } //Netbeans IDE automatically overrides this toString() public String toString() { return this.string.toString(); } }; output.write(data); dataString = output.toString(); } finally { try { inputStream.close(); } catch (Exception e) { } try { outputStream.close(); } catch (Exception e) { } } return dataString; }