List of usage examples for java.lang System setOut
public static void setOut(PrintStream out)
From source file:de.uzk.hki.da.sb.SIPBuilder.java
public static void main(String[] args) { logger.setLevel(Level.ERROR); try {// w w w. j a va 2 s . c om if (SystemUtils.IS_OS_WINDOWS) System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out), true, "CP850")); else System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out), true, "UTF-8")); } catch (UnsupportedEncodingException e) { return; } String mainFolderPath = SIPBuilder.class.getProtectionDomain().getCodeSource().getLocation().getPath(); String confFolderPath, dataFolderPath; try { mainFolderPath = URLDecoder.decode(mainFolderPath, "UTF-8"); confFolderPath = new File(mainFolderPath).getParent() + File.separator + "conf"; dataFolderPath = new File(mainFolderPath).getParent() + File.separator + "data"; } catch (UnsupportedEncodingException e) { confFolderPath = "conf"; dataFolderPath = "data"; } if (args.length == 0) startGUIMode(confFolderPath, dataFolderPath); else startCLIMode(confFolderPath, dataFolderPath, args); }
From source file:illarion.compile.Compiler.java
public static void main(final String[] args) { ByteArrayOutputStream stdOutBuffer = new ByteArrayOutputStream(); PrintStream orgStdOut = System.out; System.setOut(new PrintStream(stdOutBuffer)); SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install();/* ww w .j av a2 s .com*/ Options options = new Options(); final Option npcDir = new Option("n", "npc-dir", true, "The place where the compiled NPC files are stored."); npcDir.setArgs(1); npcDir.setArgName("directory"); npcDir.setRequired(false); options.addOption(npcDir); final Option questDir = new Option("q", "quest-dir", true, "The place where the compiled Quest files are stored."); questDir.setArgs(1); questDir.setArgName("directory"); questDir.setRequired(false); options.addOption(questDir); final Option type = new Option("t", "type", true, "This option is used to set what kind of parser is supposed to be used in case" + " the content of standard input is processed."); type.setArgs(1); type.setArgName("type"); type.setRequired(false); options.addOption(type); CommandLineParser parser = new GnuParser(); try { CommandLine cmd = parser.parse(options, args); String[] files = cmd.getArgs(); if (files.length > 0) { System.setOut(orgStdOut); stdOutBuffer.writeTo(orgStdOut); processFileMode(cmd); } else { System.setOut(orgStdOut); processStdIn(cmd); } } catch (final ParseException e) { final HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("java -jar compiler.jar [Options] File", options, true); System.exit(-1); } catch (final IOException e) { LOGGER.error(e.getLocalizedMessage()); System.exit(-1); } }
From source file:org.jetbrains.webdemo.executors.JavaExecutor.java
public static void main(String[] args) { PrintStream defaultOutputStream = System.out; try {// www .j av a 2s . com System.setOut(new PrintStream(standardOutputStream)); System.setErr(new PrintStream(errorOutputStream)); RunOutput outputObj = new RunOutput(); String className; if (args.length > 0) { className = args[0]; try { Method mainMethod = Class.forName(className).getMethod("main", String[].class); mainMethod.invoke(null, (Object) Arrays.copyOfRange(args, 1, args.length)); } catch (InvocationTargetException e) { outputObj.exception = e.getCause(); } catch (NoSuchMethodException e) { System.err.println("No main method found in project."); } catch (ClassNotFoundException e) { System.err.println("No main method found in project."); } } else { System.err.println("No main method found in project."); } System.out.flush(); System.err.flush(); System.setOut(defaultOutputStream); outputObj.text = outputStream.toString().replaceAll("</errStream><errStream>", "") .replaceAll("</outStream><outStream>", ""); ObjectMapper objectMapper = new ObjectMapper(); SimpleModule module = new SimpleModule(); module.addSerializer(Throwable.class, new ThrowableSerializer()); objectMapper.registerModule(module); System.out.print(objectMapper.writeValueAsString(outputObj)); } catch (Throwable e) { System.setOut(defaultOutputStream); System.out.println("{\"text\":\"<errStream>" + e.getClass().getName() + ": " + e.getMessage()); System.out.print("</errStream>\"}"); } }
From source file:ca.uqac.info.tag.Counter.TagCounter.java
public static void main(final String[] args) { // Parse command line arguments Options options = setupOptions();//from w ww .ja va2s .co m CommandLine c_line = setupCommandLine(args, options); String redirectionFile = ""; String tagAnalyse = ""; String inputFile = ""; if (c_line.hasOption("h")) { showUsage(options); System.exit(ERR_OK); } //Contains a redirection file for the output if (c_line.hasOption("redirection")) { try { redirectionFile = c_line.getOptionValue("redirection"); PrintStream ps; ps = new PrintStream(redirectionFile); System.setOut(ps); } catch (FileNotFoundException e) { System.out.println("Redirection error !!!"); e.printStackTrace(); } } //Contains a tag if (c_line.hasOption("Tag")) { tagAnalyse = c_line.getOptionValue("t"); } else { System.err.println("No Tag in Arguments"); System.exit(ERR_ARGUMENTS); } //Contains a InputFile if (c_line.hasOption("InputFile")) { inputFile = c_line.getOptionValue("i"); } else { System.err.println("No Input File in Arguments"); System.exit(ERR_ARGUMENTS); } //Start of the program System.out.println("-----------------------------------------------"); System.out.println("The count of the Tag is start !!!"); // Throw the Sax parsing for the file try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser; parser = factory.newSAXParser(); File Tagfile = new File(inputFile); DefaultHandler manager = new SaxTagHandlers(tagAnalyse); parser.parse(Tagfile, manager); } catch (ParserConfigurationException e) { System.out.println("Parser Configuration Exception for Sax !!!"); e.printStackTrace(); } catch (SAXException e) { System.out.println("Sax Exception during the parsing !!!"); e.printStackTrace(); } catch (IOException e) { System.out.println("Input/Ouput Exception during the Sax parsing !!!"); e.printStackTrace(); } }
From source file:de.uzk.hki.da.main.SIPBuilder.java
public static void main(String[] args) { TTCCLayout layout = new TTCCLayout(); layout.setDateFormat("yyyy'-'MM'-'dd' 'HH':'mm':'ss"); layout.setThreadPrinting(false);/*from w ww.j a v a 2s . c o m*/ ConsoleAppender consoleAppender = new ConsoleAppender(layout); logger.addAppender(consoleAppender); logger.setLevel(Level.DEBUG); properties = new Properties(); try { properties.load(new InputStreamReader( (ClassLoader.getSystemResourceAsStream("configuration/config.properties")))); } catch (FileNotFoundException e1) { System.exit(Feedback.GUI_ERROR.toInt()); } catch (IOException e2) { System.exit(Feedback.GUI_ERROR.toInt()); } try { if (SystemUtils.IS_OS_WINDOWS) System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out), true, "CP850")); else System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out), true, "UTF-8")); } catch (UnsupportedEncodingException e) { return; } String mainFolderPath = SIPBuilder.class.getProtectionDomain().getCodeSource().getLocation().getPath(); String confFolderPath, dataFolderPath; try { mainFolderPath = URLDecoder.decode(mainFolderPath, "UTF-8"); confFolderPath = new File(mainFolderPath).getParent() + File.separator + "conf"; dataFolderPath = new File(mainFolderPath).getParent() + File.separator + "data"; } catch (UnsupportedEncodingException e) { confFolderPath = "conf"; dataFolderPath = "data"; } System.out.println("ConfFolderPath:" + confFolderPath); if (args.length == 0) startGUIMode(confFolderPath, dataFolderPath); else startCLIMode(confFolderPath, dataFolderPath, args); }
From source file:net.chrislongo.hls.Main.java
public static void main(String[] args) { CommandLine commandLine = parseCommandLine(args); String[] commandLineArgs = commandLine.getArgs(); try {/*from w w w .ja va 2s . 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 {// ww w.j a va 2s.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, 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:org.jetbrains.webdemo.executors.JunitExecutor.java
public static void main(String[] args) { try {//from ww w . jav a 2 s . co m JUnitCore jUnitCore = new JUnitCore(); jUnitCore.addListener(new MyRunListener()); List<Class> classes = getAllClassesFromTheDir(new File(args[0])); for (Class cl : classes) { boolean hasTestMethods = false; for (Method method : cl.getMethods()) { if (method.isAnnotationPresent(Test.class)) { hasTestMethods = true; break; } } if (!hasTestMethods) continue; Request request = Request.aClass(cl); jUnitCore.run(request); } try { ObjectMapper objectMapper = new ObjectMapper(); SimpleModule module = new SimpleModule(); module.addSerializer(Throwable.class, new ThrowableSerializer()); module.addSerializer(junit.framework.ComparisonFailure.class, new JunitFrameworkComparisonFailureSerializer()); module.addSerializer(org.junit.ComparisonFailure.class, new OrgJunitComparisonFailureSerializer()); objectMapper.registerModule(module); System.setOut(standardOutput); Map<String, List<TestRunInfo>> groupedTestResults = new HashMap<>(); for (TestRunInfo testRunInfo : output) { if (!groupedTestResults.containsKey(testRunInfo.className)) { groupedTestResults.put(testRunInfo.className, new ArrayList<TestRunInfo>()); } groupedTestResults.get(testRunInfo.className).add(testRunInfo); } System.out.print(objectMapper.writeValueAsString(groupedTestResults)); } catch (IOException e) { e.printStackTrace(); } } catch (Throwable e) { System.setOut(standardOutput); System.out.print("[\""); e.printStackTrace(); System.out.print("\"]"); } }
From source file:de.peran.DependencyReadingStarter.java
public static void main(final String[] args) throws ParseException, FileNotFoundException { final Options options = OptionConstants.createOptions(OptionConstants.FOLDER, OptionConstants.STARTVERSION, OptionConstants.ENDVERSION, OptionConstants.OUT); final CommandLineParser parser = new DefaultParser(); final CommandLine line = parser.parse(options, args); final File projectFolder = new File(line.getOptionValue(OptionConstants.FOLDER.getName())); final File dependencyFile; if (line.hasOption(OptionConstants.OUT.getName())) { dependencyFile = new File(line.getOptionValue(OptionConstants.OUT.getName())); } else {/*from ww w. j av a 2 s .co m*/ dependencyFile = new File("dependencies.xml"); } File outputFile = projectFolder.getParentFile(); if (outputFile.isDirectory()) { outputFile = new File(projectFolder.getParentFile(), "ausgabe.txt"); } LOG.debug("Lese {}", projectFolder.getAbsolutePath()); final VersionControlSystem vcs = VersionControlSystem.getVersionControlSystem(projectFolder); System.setOut(new PrintStream(outputFile)); // System.setErr(new PrintStream(outputFile)); final DependencyReader reader; if (vcs.equals(VersionControlSystem.SVN)) { final String url = SVNUtils.getInstance().getWCURL(projectFolder); final List<SVNLogEntry> entries = getSVNCommits(line, url); LOG.debug("SVN commits: " + entries.stream().map(entry -> entry.getRevision()).collect(Collectors.toList())); reader = new DependencyReader(projectFolder, url, dependencyFile, entries); } else if (vcs.equals(VersionControlSystem.GIT)) { final List<GitCommit> commits = getGitCommits(line, projectFolder); reader = new DependencyReader(projectFolder, dependencyFile, commits); LOG.debug("Reader initalized"); } else { throw new RuntimeException("Unknown version control system"); } reader.readDependencies(); }
From source file:net.yash069.hls.Main.java
public static void main(String[] args) { CommandLine commandLine = parseCommandLine(args); String[] commandLineArgs = commandLine.getArgs(); try {/*from w ww. j av a 2 s . c o m*/ 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); } }