Example usage for org.apache.commons.io IOUtils readLines

List of usage examples for org.apache.commons.io IOUtils readLines

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils readLines.

Prototype

public static List readLines(Reader input) throws IOException 

Source Link

Document

Get the contents of a Reader as a list of Strings, one entry per line.

Usage

From source file:com.fluke.application.EODReader.java

public static void main(String[] args) throws IOException, ParseException, SQLException {
    List<String> list = IOUtils.readLines(ClassLoader.getSystemResourceAsStream("config/stocks"));
    new EODDao().deleteLastData();

    for (String eq : new EquityDao().getAllEquity()) {
        System.out.println("" + eq);
        YahooEODParser parser = new YahooEODParser(eq);
        parser.process();//from ww w  . j a  v  a2s .co m
    }
}

From source file:com.fluke.application.IEODReader.java

public static void main(String[] args) throws IOException {
    String location = "/home/arshed/Pictures/sample";
    list = IOUtils.readLines(ClassLoader.getSystemResourceAsStream("config/stocks"));
    File folder = new File(location);
    processFolder(Arrays.asList(folder));

}

From source file:de.tudarmstadt.ukp.experiments.argumentation.clustering.entropy.MatrixExperiments.java

public static void main(String[] args) throws Exception {
    File in = new File(args[0]);

    List<String> lines = IOUtils.readLines(new FileInputStream(in));

    int rows = lines.size();
    int cols = lines.iterator().next().split("\\s+").length;

    double[][] matrix = new double[rows][cols];

    Map<Integer, Double> clusterEntropy = new HashMap<>();

    for (int i = 0; i < rows; i++) {
        String line = lines.get(i);

        String[] split = line.split("\\s+");

        for (int j = 0; j < split.length; j++) {
            Double value = Double.valueOf(split[j]);

            matrix[i][j] = value;/*from   w  ww.j  a  v a  2  s  .  c om*/
        }

        // entropy of the cluster
        Vector v = new DenseVector(matrix[i]);
        //            System.out.print(VectorUtils.entropy(v));
        double entropy = VectorUtils.entropy(VectorUtils.normalize(v));
        System.out.print(entropy);
        System.out.print(" ");

        clusterEntropy.put(i, entropy);
    }

    Map<Integer, Double> sorted = sortByValue(clusterEntropy);
    System.out.println(sorted);

    HeatChart map = new HeatChart(matrix);

    // Step 2: Customise the chart.
    map.setTitle("This is my heat chart title");
    map.setXAxisLabel("X Axis");
    map.setYAxisLabel("Y Axis");

    // Step 3: Output the chart to a file.
    map.saveToFile(new File("/tmp/java-heat-chart.png"));

}

From source file:CommandsFromZipFile.java

/**
 *  Sample test to retrieve command value using zip file
 * @param args/*  w  w  w.  j a v  a 2s  .c o m*/
 */
public static void main(String[] args) {
    //by default it sets to Ctrl+D
    System.setProperty("jline.shutdownhook", "true");
    try {
        ConsoleReader consoleReader = new ConsoleReader();
        consoleReader.setPrompt("carbon>");
        consoleReader.addCompleter(new StringsCompleter(IOUtils.readLines(
                new GZIPInputStream(CommandsFromZipFile.class.getResourceAsStream("commandList.txt.gz")))));
        consoleReader.addCompleter(new FileNameCompleter());
        String line = "";
        String colored = "";

        while ((line = consoleReader.readLine()) != null) {
            if ("clear".equals(line.trim())) {
                System.out.print("\33[2J");
                System.out.flush();
                System.out.print("\33[1;1H");
                System.out.flush();
            } else if ("aback".equals(line.trim())) {
                colored = Ansi.ansi().fg(Ansi.Color.RED).a("Entered command : ")
                        .a(Ansi.Attribute.INTENSITY_BOLD).a(line).a(Ansi.Attribute.INTENSITY_BOLD_OFF)
                        .fg(Ansi.Color.DEFAULT).toString();
                consoleReader.println(colored);
            } else {
                consoleReader.println(line);
            }
        }
    } catch (IOException exception) {
        LOGGER.error(" Unable to load commands from the zip file ", exception);
    } finally {
        try {
            jline.TerminalFactory.get().restore();
        } catch (Exception exception) {
            LOGGER.error(" Unable to restore the terminal ", exception);
        }
    }
}

From source file:com.linkedin.pinot.perf.MultiValueReaderWriterBenchmark.java

public static void main(String[] args) throws Exception {
    List<String> lines = IOUtils.readLines(new FileReader(new File(args[0])));
    int totalDocs = lines.size();
    int max = Integer.MIN_VALUE;
    int maxNumberOfMultiValues = Integer.MIN_VALUE;
    int totalNumValues = 0;
    int data[][] = new int[totalDocs][];
    for (int i = 0; i < lines.size(); i++) {
        String line = lines.get(i);
        String[] split = line.split(",");
        totalNumValues = totalNumValues + split.length;
        if (split.length > maxNumberOfMultiValues) {
            maxNumberOfMultiValues = split.length;
        }//from w  w w .  j  a v a 2 s. com
        data[i] = new int[split.length];
        for (int j = 0; j < split.length; j++) {
            String token = split[j];
            int val = Integer.parseInt(token);
            data[i][j] = val;
            if (val > max) {
                max = val;
            }
        }
    }
    int maxBitsNeeded = (int) Math.ceil(Math.log(max) / Math.log(2));
    int size = 2048;
    int[] offsets = new int[size];
    int bitMapSize = 0;
    File outputFile = new File("output.mv.fwd");

    FixedBitSkipListSCMVWriter fixedBitSkipListSCMVWriter = new FixedBitSkipListSCMVWriter(outputFile,
            totalDocs, totalNumValues, maxBitsNeeded);

    for (int i = 0; i < totalDocs; i++) {
        fixedBitSkipListSCMVWriter.setIntArray(i, data[i]);
        if (i % size == size - 1) {
            MutableRoaringBitmap rr1 = MutableRoaringBitmap.bitmapOf(offsets);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(bos);
            rr1.serialize(dos);
            dos.close();
            //System.out.println("Chunk " + i / size + " bitmap size:" + bos.size());
            bitMapSize += bos.size();
        } else if (i == totalDocs - 1) {
            MutableRoaringBitmap rr1 = MutableRoaringBitmap.bitmapOf(Arrays.copyOf(offsets, i % size));
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(bos);
            rr1.serialize(dos);
            dos.close();
            //System.out.println("Chunk " + i / size + " bitmap size:" + bos.size());
            bitMapSize += bos.size();
        }
    }
    fixedBitSkipListSCMVWriter.close();
    System.out.println("Output file size:" + outputFile.length());
    System.out.println("totalNumberOfDoc\t\t\t:" + totalDocs);
    System.out.println("totalNumberOfValues\t\t\t:" + totalNumValues);
    System.out.println("chunk size\t\t\t\t:" + size);
    System.out.println("Num chunks\t\t\t\t:" + totalDocs / size);
    int numChunks = totalDocs / size + 1;
    int totalBits = (totalNumValues * maxBitsNeeded);
    int dataSizeinBytes = (totalBits + 7) / 8;

    System.out.println("Raw data size with fixed bit encoding\t:" + dataSizeinBytes);
    System.out.println("\nPer encoding size");
    System.out.println();
    System.out.println("size (offset + length)\t\t\t:" + ((totalDocs * (4 + 4)) + dataSizeinBytes));
    System.out.println();
    System.out.println("size (offset only)\t\t\t:" + ((totalDocs * (4)) + dataSizeinBytes));
    System.out.println();
    System.out.println("bitMapSize\t\t\t\t:" + bitMapSize);
    System.out.println("size (with bitmap)\t\t\t:" + (bitMapSize + (numChunks * 4) + dataSizeinBytes));

    System.out.println();
    System.out.println("Custom Bitset\t\t\t\t:" + (totalNumValues + 7) / 8);
    System.out.println("size (with custom bitset)\t\t\t:"
            + (((totalNumValues + 7) / 8) + (numChunks * 4) + dataSizeinBytes));

}

From source file:com.vaadin.buildhelpers.FetchReleaseNotesTickets.java

public static void main(String[] args) throws IOException {
    String version = System.getProperty("vaadin.version");
    if (version == null || version.equals("")) {
        usage();/*w ww . j a  v  a2  s .c om*/
    }

    URL url = new URL(queryURL.replace("@version@", version));
    URLConnection connection = url.openConnection();
    InputStream urlStream = connection.getInputStream();

    @SuppressWarnings("unchecked")
    List<String> tickets = IOUtils.readLines(urlStream);

    for (String ticket : tickets) {
        String[] fields = ticket.split("\t");
        if ("id".equals(fields[0])) {
            // This is the header
            continue;
        }
        System.out.println(ticketTemplate.replace("@ticket@", fields[0]).replace("@description@", fields[1]));
    }
    urlStream.close();
}

From source file:de.andrena.tools.macker.plugin.CommandLineFile.java

public static void main(String[] args) throws Exception {
    if (args.length == 0 || args.length > 2) {
        System.err.println("Usage: CommandLineFile <main class> [command line arguments file]");
        System.exit(1);//from w  w w  .  java2  s.co m
    }

    String className = args[0];
    Class<?> clazz = Class.forName(className);
    Method main = clazz.getMethod("main", new Class[] { String[].class });

    List<String> lines = new ArrayList<String>();
    if (args.length == 2) {
        Reader in = new InputStreamReader(new FileInputStream(args[1]), "UTF-8");
        try {
            lines = IOUtils.readLines(in);
        } finally {
            in.close();
        }
    }

    try {
        main.invoke(null, new Object[] { lines.toArray(new String[lines.size()]) });
    } catch (InvocationTargetException ex) {
        Throwable cause = ex.getTargetException();
        if (cause instanceof Error) {
            throw (Error) cause;
        }
        throw (Exception) cause;
    }
}

From source file:com.me.jvmi.Main.java

public static void main(String[] args) throws IOException {

    final Path localProductImagesPath = Paths.get("/Volumes/jvmpubfs/WEB/images/products/");
    final Path uploadCSVFile = Paths.get("/Users/jbabic/Documents/products/upload.csv");
    final Config config = new Config(Paths.get("../config.properties"));

    LuminateOnlineClient luminateClient2 = new LuminateOnlineClient("https://secure2.convio.net/jvmi/admin/",
            3);/*from  ww w. j a v a2 s.  c  om*/
    luminateClient2.login(config.luminateUser(), config.luminatePassword());

    Set<String> completed = new HashSet<>(
            IOUtils.readLines(Files.newBufferedReader(Paths.get("completed.txt"))));

    try (InputStream is = Files.newInputStream(Paths.get("donforms.csv"));
            PrintWriter pw = new PrintWriter(new FileOutputStream(new File("completed.txt"), true))) {

        for (String line : IOUtils.readLines(is)) {
            if (completed.contains(line)) {
                System.out.println("completed: " + line);
                continue;
            }
            try {
                luminateClient2.editDonationForm(line, "-1");
                pw.println(line);
                System.out.println("done: " + line);
                pw.flush();
            } catch (Exception e) {
                System.out.println("skipping: " + line);
                e.printStackTrace();
            }
        }
    }

    //        luminateClient2.editDonationForm("8840", "-1");
    //        Collection<String> ids = luminateClient2.donFormSearch("", true);
    //        
    //        CSVFormat csvFileFormat = CSVFormat.DEFAULT.withRecordSeparator("\n");
    //        try (FileWriter fileWriter = new FileWriter(new File("donforms.csv"));
    //                CSVPrinter csvFilePrinter = new CSVPrinter(fileWriter, csvFileFormat);) {
    //
    //            for (String id : ids) {
    //                csvFilePrinter.printRecord(id);
    //            }
    //        }
    //        

    if (true) {
        return;
    }

    Collection<InputRecord> records = parseInput(uploadCSVFile);

    LuminateFTPClient ftp = new LuminateFTPClient("customerftp.convio.net");
    ftp.login(config.ftpUser(), config.ftpPassword());

    ProductImages images = new ProductImages(localProductImagesPath, ftp);

    validateImages(records, images);

    Map<String, DPCSClient> dpcsClients = new HashMap<>();
    dpcsClients.put("us", new DPCSClient("https://donor.dpconsulting.com/NewDDI/Logon.asp?client=jvm"));
    dpcsClients.put("ca", new DPCSClient("https://donor.dpconsulting.com/NewDDI/Logon.asp?client=jvcn"));
    dpcsClients.put("uk", new DPCSClient("https://donor.dpconsulting.com/NewDDI/Logon.asp?client=jvuk"));

    for (DPCSClient client : dpcsClients.values()) {
        client.login(config.dpcsUser(), config.dpcsPassword());
    }

    Map<String, LuminateOnlineClient> luminateClients = new HashMap<>();
    luminateClients.put("us", new LuminateOnlineClient("https://secure2.convio.net/jvmi/admin/", 10));
    luminateClients.put("ca", new LuminateOnlineClient("https://secure3.convio.net/jvmica/admin/", 10));
    luminateClients.put("uk", new LuminateOnlineClient("https://secure3.convio.net/jvmiuk/admin/", 10));

    Map<String, EcommerceProductFactory> ecommFactories = new HashMap<>();
    ecommFactories.put("us", new EcommerceProductFactory(dpcsClients.get("us"), images, Categories.us));
    ecommFactories.put("ca", new EcommerceProductFactory(dpcsClients.get("ca"), images, Categories.ca));
    ecommFactories.put("uk", new EcommerceProductFactory(dpcsClients.get("uk"), images, Categories.uk));

    List<String> countries = Arrays.asList("us", "ca", "uk");

    boolean error = false;
    for (InputRecord record : records) {
        for (String country : countries) {
            if (record.ignore(country)) {
                System.out.println("IGNORE: " + country + " " + record);
                continue;
            }
            try {
                EcommerceProductFactory ecommFactory = ecommFactories.get(country);
                LuminateOnlineClient luminateClient = luminateClients.get(country);
                luminateClient.login(config.luminateUser(), config.luminatePassword());

                ECommerceProduct product = ecommFactory.createECommerceProduct(record);
                luminateClient.createOrUpdateProduct(product);
            } catch (Exception e) {
                System.out.println("ERROR: " + country + " " + record);
                //System.out.println(e.getMessage());
                error = true;
                e.printStackTrace();
            }
        }
    }

    if (!error) {
        for (String country : countries) {
            LuminateOnlineClient luminateClient = luminateClients.get(country);
            DPCSClient dpcsClient = dpcsClients.get(country);
            luminateClient.close();
            dpcsClient.close();
        }
    }
}

From source file:eu.annocultor.utils.OntologySubtractor.java

public static void main(String[] args) throws Exception {

    boolean copy = checkNoCopyOption(args);

    if (args.length == 2 || args.length == 3) {

        File sourceDir = new File(args[0]);
        File destinationDir = new File(args[1]);

        checkSrcAndDstDirs(sourceDir, destinationDir);

        Collection<String> filesWithDeletedStatements = listNameStamsForFilesWithDeletedStatements(sourceDir);

        if (filesWithDeletedStatements.isEmpty()) {
            System.out.println(//from  www.  j ava 2 s  .co m
                    "Did not found any file *.*.*.deleted.rdf with statements to be deleted. Do nothing and exit.");
        } else {

            System.out.println(
                    "Found " + filesWithDeletedStatements.size() + " files with statements to be deleted");
            System.out.println(
                    "Copying all RDF files from " + sourceDir.getName() + " to " + destinationDir.getName());

            if (copy) {
                copyRdfFiles(sourceDir, destinationDir);
            }

            sutractAll(sourceDir, destinationDir, filesWithDeletedStatements);
        }
    } else {
        for (Object string : IOUtils.readLines(new AutoCloseInputStream(
                OntologySubtractor.class.getResourceAsStream("/subtractor/readme.txt")))) {
            System.out.println(string.toString());
        }
    }
}

From source file:it.unimi.di.big.mg4j.document.WarcDocumentSequence_NYU.java

public static void main(String[] args) throws Exception {

    SimpleJSAP jsap = new SimpleJSAP(WarcDocumentSequence_NYU.class.getName(),
            "Saves a serialised Warc document sequence based on a set of file names.",
            new Parameter[] {
                    new FlaggedOption("factory", JSAP.CLASS_PARSER, IdentityDocumentFactory.class.getName(),
                            JSAP.NOT_REQUIRED, 'f', "factory",
                            "A document factory with a standard constructor."),
                    new FlaggedOption("property", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'p',
                            "property", "A 'key=value' specification, or the name of a property file")
                                    .setAllowMultipleDeclarations(true),
                    new Switch("gzip", 'z', "gzip",
                            "Expect gzip-ed WARC content (files should end in .warc.gz)."),
                    new FlaggedOption("bufferSize", JSAP.INTSIZE_PARSER, DEFAULT_BUFFER_SIZE, JSAP.NOT_REQUIRED,
                            'b', "buffer-size", "The size of an I/O buffer."),
                    new UnflaggedOption("sequence", JSAP.STRING_PARSER, JSAP.REQUIRED,
                            "The filename for the serialized sequence."),
                    new UnflaggedOption("basename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED,
                            JSAP.GREEDY,
                            "A list of basename files that will be indexed. If missing, a list of files will be read from standard input.") });

    final JSAPResult jsapResult = jsap.parse(args);
    if (jsap.messagePrinted())
        System.exit(1);//from w  ww  . j  av a 2  s .  c o  m

    final DocumentFactory factory = PropertyBasedDocumentFactory.getInstance(jsapResult.getClass("factory"),
            jsapResult.getStringArray("property"));
    final boolean isGZipped = jsapResult.getBoolean("gzip");

    String[] file = jsapResult.getStringArray("basename");
    if (file.length == 0)
        file = IOUtils.readLines(System.in).toArray(new String[0]);
    if (file.length == 0)
        LOGGER.warn("Empty fileset");

    BinIO.storeObject(new WarcDocumentSequence_NYU(file, factory, isGZipped, jsapResult.getInt("bufferSize")),
            jsapResult.getString("sequence"));
}