static void usage() { System.err.printf("Usage: java %s <query-file> <k> <out-file>\n", WordCluster.class.getName()); System.err.println("\t<query-file> contains word projections in the text format\n"); System.err.println("\t<k> number of clustering\n"); System.err.println("\t<out-file> output file\n"); System.exit(0); }
public static void main(String[] args) throws IOException { if (args.length < 1) { log.info(usage); System.exit(1); } Properties options = StringUtils.argsToProperties(args, argOptionDefs); String outputPath = options.getProperty("o"); if (outputPath == null) throw new IllegalArgumentException("-o argument (output path for built tagger) is required"); String[] remainingArgs = options.getProperty("").split(" "); List<File> fileList = new ArrayList<>(); for (String arg : remainingArgs) fileList.add(new File(arg)); AnCoraPOSStats stats = new AnCoraPOSStats(fileList, outputPath); stats.process(); ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(outputPath)); TwoDimensionalCounter<String, String> tagger = stats.getUnigramTagger(); oos.writeObject(tagger); System.out.printf("Wrote tagger to %s%n", outputPath); }
import java.util.*; public class GarbageCollector { public static void main(String... args) { System.out.printf("Testing...%n"); List<Double> list = new ArrayList<Double>(); for (int outer = 0; outer < 10000; outer++) { // list = new ArrayList<Double>(10000); // BAD // list = new ArrayList<Double>(); // WORSE list.clear(); // BETTER for (int inner = 0; inner < 10000; inner++) { list.add(Math.random()); } if (outer % 1000 == 0) { System.out.printf("Outer loop at %d%n", outer); } } System.out.printf("Done.%n"); } }
public static void main(String[] args) throws IOException { // 1. create the pipes PipedInputStream inPipe = new PipedInputStream(); PipedInputStream outPipe = new PipedInputStream(); // 2. set the System.in and System.out streams System.setIn(inPipe); System.setOut(new PrintStream(new PipedOutputStream(outPipe), true)); PrintWriter inWriter = new PrintWriter(new PipedOutputStream(inPipe), true); // 3. create the gui JFrame frame = new JFrame("\"Console\""); frame.add(console(outPipe, inWriter)); frame.setSize(400, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); // 4. write some output (to JTextArea) System.out.println("Hello World!"); System.out.println("Test"); System.out.println("Test"); System.out.println("Test"); // 5. get some input (from JTextArea) Scanner s = new Scanner(System.in); System.out.printf("got from input: \"%s\"%n", s.nextLine()); }
System.out.println("Comparing line breaking performance of different solutions"); System.out.printf("Testing %d lines%n", lineCount); String text = createText(lineCount); testSplitAllPlatforms(text); long start = System.currentTimeMillis(); text.split("\n\r|\r"); System.out.printf("Split (regexp): %d%n", System.currentTimeMillis() - start); long start = System.currentTimeMillis(); text.split("\n"); System.out.printf("Split (CR only): %d%n", System.currentTimeMillis() - start); List<String> result = new ArrayList<>(); try (Scanner scanner = new Scanner(text)) { while (scanner.hasNextLine()) { result.add(scanner.nextLine()); System.out.printf("Scanner: %d%n", System.currentTimeMillis() - start); List<String> result = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(new StringReader(text))) { String line = reader.readLine(); while (line != null) { result.add(line); line = reader.readLine(); System.out.printf("Reader: %d%n", System.currentTimeMillis() - start);
fileQuickSort( new File("input"), new File("output")); System.out.println(); Scanner scanner = new Scanner( new BufferedInputStream( new FileInputStream( inputFile ), MAX_SIZE)); scanner.useDelimiter(","); System.out.print("-"); int current = scanner.nextInt(); target = greater; target.printf("%d,",current); greater.printf("%d,",pivot); System.out.print("."); List<Integer> smallFileIntegers = new ArrayList<Integer>(); smallFileIntegers.add( scanner.nextInt() ); out.printf("%d,",i);
} else if (arg.equals(ARG_CONFIG)) { if (index == args.length - 1 || !args[index + 1].endsWith(TypedValue.FILE_XML)) { System.err.println("Missing XML configuration file argument"); goToError(); configFile = new File(args[++index]); if (!configFile.exists()) { System.err.println(configFile.getAbsolutePath() + " does not exist"); goToError(); System.out.println("special configFile file path:" + configFile.getAbsolutePath()); goToError(); outputFile = new File(args[++index]); File parent = outputFile.getParentFile(); if (parent != null && (!parent.exists())) { parent.mkdirs(); System.out.printf("special output directory path: %s\n", outputFile.getAbsolutePath()); goToError(); oldApkFile = new File(args[++index]); } else if (arg.equals(ARG_NEW)) { if (index == args.length - 1) {
/** * Load trees from given directory. This version just records * the paths to be processed, and actually processes them at apply time. * * @param path file or directory to load from * @param filt a FilenameFilter of files to load */ @Override public void loadPath(File path, FileFilter filt) { if(path.exists()) { filePaths.add(path); fileFilters.add(filt); } else { System.err.printf("%s: File/path %s does not exist. Skipping.%n" , this.getClass().getName(), path.getPath()); } }
final String diffStr = "% diff"; out.print('|'); printCell(numBytesStr, 0, out); printCell(numThreadsStr, 0, out); for (int i = 0; i < crcs.size(); i++) { final Class<? extends Checksum> c = crcs.get(i); out.print('|'); printCell(c.getSimpleName(), 8, out); for(int j = 0; j < i; j++) { out.printf("\n"); out.printf("|"); printCell(String.valueOf(size), numBytesStr.length(), out); printCell(String.valueOf(numThreads), numThreadsStr.length(), out); final List<BenchResult> previous = new ArrayList<BenchResult>(); for(final Class<? extends Checksum> c : crcs) { System.gc(); printCell(String.format("%5.1f%%", diff), diffStr.length(), out); previous.add(result); out.printf("\n");
/** * 读取整个目录中的人民日报格式语料 * * @param folderPath 路径 * @param verbose * @return */ public static List<Document> convert2DocumentList(String folderPath, boolean verbose) { long start = System.currentTimeMillis(); List<File> fileList = IOUtil.fileList(folderPath); List<Document> documentList = new LinkedList<Document>(); int i = 0; for (File file : fileList) { if (verbose) System.out.print(file); Document document = convert2Document(file); documentList.add(document); if (verbose) System.out.println(" " + ++i + " / " + fileList.size()); } if (verbose) { System.out.println(documentList.size()); System.out.printf("花费时间%d ms\n", System.currentTimeMillis() - start); } return documentList; }
public boolean setOptions(Properties opts) { for(String opt : opts.stringPropertyNames()) { String value = opts.getProperty(opt); if(value == null) { System.err.printf("%s: Read parameter with null value (%s)\n", this.getClass().getName(),opt); continue; } configuredOptions.add(opt); Matcher pathMatcher = ConfigParser.matchPath.matcher(opt); if(pathMatcher.lookingAt()) { pathsToData.add(new File(value)); configuredOptions.add(ConfigParser.paramPath); } else if(opt.equals(ConfigParser.paramName)) { Matcher inThisFilename = fileNameNormalizer.matcher(value.trim()); outFileName = inThisFilename.replaceAll("-"); toStringBuffer.append(String.format("Dataset Name: %s\n",value.trim())); } } if(!configuredOptions.containsAll(requiredOptions)) return false; //Finalize the output file names outFileName += ".txt"; //Used for codifying lexical hacks lexMapper = new DefaultLexicalMapper(); return true; }
List<Integer> nodeIds = Lists.newArrayList(); System.out.print("\nNew metadata: \n" + value.toString() + "\n"); System.out.print("\nAffected nodes:\n"); System.out.format("+-------+------+---------------------------------+----------+---------+------------------+%n"); System.out.printf("|Id |Zone |Host |SocketPort|AdminPort|NumberOfPartitions|%n"); System.out.format("+-------+------+---------------------------------+----------+---------+------------------+%n"); nodeIds.add(node.getId()); System.out.format("| %-5d | %-4d | %-31s | %-5d | %-5d | %-5d |%n", node.getId(), System.out.print("Do you want to proceed? [Y/N]: "); Scanner in = new Scanner(System.in); String choice = in.nextLine(); return false; } else { System.out.println("Incorrect response detected. Exiting."); return false;
public static void walk(String folderPath, Handler handler) { long start = System.currentTimeMillis(); List<File> fileList = IOUtil.fileList(folderPath); int i = 0; for (File file : fileList) { System.out.print(file); Document document = convert2Document(file); System.out.println(" " + ++i + " / " + fileList.size()); handler.handle(document); } System.out.printf("花费时间%d ms\n", System.currentTimeMillis() - start); }
private static void runPerfTests(final String[] args, final List<Setup> tests) throws IOException, InterruptedException, FileNotFoundException { final String java = args.length > 0 ? args[0] : "java"; final int repeat = args.length > 1 ? Integer.parseInt(args[1]) : 5; int x = 0; for (final Setup setup : tests) { System.out.print(setup.description()); final ProcessBuilder pb = setup.throughputTest(java); pb.redirectErrorStream(true); // merge System.out and System.err final long t1 = System.nanoTime(); final int count = setup.threadCount >= 4 ? 3 : repeat; runPerfTest(count, x++, setup, pb); System.out.printf(" took %.1f seconds%n", (System.nanoTime() - t1) / (1000.0 * 1000.0 * 1000.0)); final FileReader reader = new FileReader(setup.temp); final CharBuffer buffer = CharBuffer.allocate(256 * 1024); reader.read(buffer); reader.close(); setup.temp.delete(); buffer.flip(); final String raw = buffer.toString(); System.out.print(raw); final Stats stats = new Stats(raw); System.out.println(stats); System.out.println("-----"); setup.stats = stats; } new File("perftest.log").delete(); }
@Nonnull String symlinkPath, @Nonnull TaskListener listener) throws InterruptedException { try { Path path = fileToPath(new File(baseDir, symlinkPath)); Path target = Paths.get(targetPath, MemoryReductionUtil.EMPTY_STRING_ARRAY); log.print("Symbolic links are not supported on this platform"); Functions.printStackTrace(e, log); } catch (IOException e) { log.printf("ln %s %s failed%n",targetPath, new File(baseDir, symlinkPath)); Functions.printStackTrace(e, log);
public void run() { Scanner sc = new Scanner(p.getErrorStream()); + Integer.parseInt(hms[1]) * 60 + Double.parseDouble(hms[2]); System.out.println("Total duration: " + totalSecs + " seconds."); while (null != (match = sc.findWithinHorizon(timePattern, 0))) { double progress = Double.parseDouble(match) / totalSecs; System.out.printf("Progress: %.2f%%%n", progress * 100);
public static void main(String[] arg) { Scanner keyboard = new Scanner(System.in); System.out.print("Type a string: "); String word = keyboard.nextLine(); System.out.printf ("New string: %s", removeVowels(word)); System.out.print ("\nThank you for using the system"); } public static String removeVowels (String word) { String str=word; str = str.replaceAll("[AEIOUaeiou]", ""); return word; }
scanner = new Scanner(System.in); Result result = null; while ((result = getTargetVector()) != null) System.out.printf("\n Word Cosine cosine\n------------------------------------------------------------------------\n"); for (int j = 0; j < N; j++) System.out.printf("%50s\t\t%f\n", bestw[j], bestd[j]);