Example usage for java.util Scanner next

List of usage examples for java.util Scanner next

Introduction

In this page you can find the example usage for java.util Scanner next.

Prototype

public String next() 

Source Link

Document

Finds and returns the next complete token from this scanner.

Usage

From source file:edu.harvard.iq.dataverse.dataaccess.TabularSubsetGenerator.java

public static Double[] subsetDoubleVector(InputStream in, int column, int numCases) {
    Double[] retVector = new Double[numCases];
    Scanner scanner = new Scanner(in);
    scanner.useDelimiter("\\n");

    for (int caseIndex = 0; caseIndex < numCases; caseIndex++) {
        if (scanner.hasNext()) {
            String[] line = (scanner.next()).split("\t", -1);

            // Verified: new Double("nan") works correctly, 
            // resulting in Double.NaN;
            // Double("[+-]Inf") doesn't work however; 
            // (the constructor appears to be expecting it
            // to be spelled as "Infinity", "-Infinity", etc. 
            if ("inf".equalsIgnoreCase(line[column]) || "+inf".equalsIgnoreCase(line[column])) {
                retVector[caseIndex] = java.lang.Double.POSITIVE_INFINITY;
            } else if ("-inf".equalsIgnoreCase(line[column])) {
                retVector[caseIndex] = java.lang.Double.NEGATIVE_INFINITY;
            } else if (line[column] == null || line[column].equals("")) {
                // missing value:
                retVector[caseIndex] = null;
            } else {
                try {
                    retVector[caseIndex] = new Double(line[column]);
                } catch (NumberFormatException ex) {
                    retVector[caseIndex] = null; // missing value
                }//  ww w  .j  a  v  a  2s.  c  o  m
            }

        } else {
            scanner.close();
            throw new RuntimeException("Tab file has fewer rows than the stored number of cases!");
        }
    }

    int tailIndex = numCases;
    while (scanner.hasNext()) {
        String nextLine = scanner.next();
        if (!"".equals(nextLine)) {
            scanner.close();
            throw new RuntimeException(
                    "Column " + column + ": tab file has more nonempty rows than the stored number of cases ("
                            + numCases + ")! current index: " + tailIndex + ", line: " + nextLine);
        }
        tailIndex++;
    }

    scanner.close();
    return retVector;

}

From source file:com.twitter.ambrose.hive.AmbroseHiveFinishHook.java

private String getLastCmd() {
    CliSessionState cliss = (CliSessionState) SessionState.get();
    Scanner scanner = null;
    try {/*w ww. j  a  va 2 s .  c  o m*/
        scanner = new Scanner(new File(cliss.fileName));
    } catch (FileNotFoundException e) {
        LOG.error("Can't find Hive script", e);
    }
    if (scanner == null) {
        return null;
    }
    Pattern delim = Pattern.compile(";");
    scanner.useDelimiter(delim);
    String lastLine = null;
    while (scanner.hasNext()) {
        String line = StringUtils.trim(scanner.next().replaceAll("\\n|\\r", ""));
        if (line.length() != 0 && !line.startsWith("--")) {
            lastLine = line;
        }
    }
    return lastLine;
}

From source file:edu.american.student.stonewall.display.html.framework.HTMLElement.java

private List<Browser> getBrowsersToCheck() {
    List<Browser> toReturn = new ArrayList<Browser>();
    InputStream is = this.getClass().getClassLoader().getResourceAsStream("browsers.conf");
    if (is != null) {
        Scanner in = new Scanner(is);
        in.useDelimiter("\n");
        while (in.hasNext()) {
            String line = in.next();
            toReturn.add(Browser.getBrowser(line));
        }/*  ww  w.jav  a 2  s .  c o m*/
    } else {
        log.warn("Ignoring browser check. browsers.conf not found!");
    }
    return toReturn;
}

From source file:reittienEtsinta.Kayttoliittyma.java

public void kaynnista() {
    Scanner lukija = new Scanner(System.in);
    System.out.println("Komennot: \n" + " koord <lon> <lat> <lon> <lat> <tiedostonimi> \n "
            + "hae <lahtosolmu> <maalisolmu> <tiedostonimi> \n " + "kaari <lahtosolmu> <maalisolmu>\n"
            + "lopeta");
    while (true) {
        String komento = lukija.nextLine();
        if (komento.substring(0, 5).equals("koord")) {
            Scanner komentotulkki = new Scanner(komento);

            double lonA = Double.parseDouble(komentotulkki.findInLine("[0-9]{6}"));
            double latA = Double.parseDouble(komentotulkki.findInLine("[0-9]{7}"));
            double lonM = Double.parseDouble(komentotulkki.findInLine("[0-9]{6}"));
            double latM = Double.parseDouble(komentotulkki.findInLine("[0-9]{7}"));

            this.haeReittiKoordinaateilla(latA, lonA, latM, lonM);

            String polku = komentotulkki.next();
            this.tallennaReitti(polku);
        } else if (komento.substring(0, 3).equals("hae")) {
            Scanner komentotulkki = new Scanner(komento);
            int alku = Integer.parseInt(komentotulkki.findInLine("[0-9]{1,4}"));
            int maali = Integer.parseInt(komentotulkki.findInLine("[0-9]{1,4}"));

            this.haeReitti(alku, maali);
            String polku = komentotulkki.next();
            this.tallennaReitti(polku);

        } else if (komento.substring(0, 5).equals("kaari")) {
            Scanner komentotulkki = new Scanner(komento);
            int alku = Integer.parseInt(komentotulkki.findInLine("[0-9]{1,4}"));
            int maali = Integer.parseInt(komentotulkki.findInLine("[0-9]{1,4}"));

            this.haeKaari(alku, maali);

        } else if (komento.equals("lopeta")) {
            return;
        } else {//from  www. ja  va 2 s.  c  o  m
            System.out.println("tuntematon komento");
        }
    }

}

From source file:com.photon.phresco.plugin.commons.PluginUtils.java

public void executeSql(SettingsInfo info, File basedir, String filePath, String fileName)
        throws PhrescoException {
    initDriverMap();//from   w ww  . j a v a2s  .  c  o m
    String host = info.getPropertyInfo(Constants.DB_HOST).getValue();
    String port = info.getPropertyInfo(Constants.DB_PORT).getValue();
    String userName = info.getPropertyInfo(Constants.DB_USERNAME).getValue();
    String password = info.getPropertyInfo(Constants.DB_PASSWORD).getValue();
    String databaseName = info.getPropertyInfo(Constants.DB_NAME).getValue();
    String databaseType = info.getPropertyInfo(Constants.DB_TYPE).getValue();
    String version = info.getPropertyInfo(Constants.DB_VERSION).getValue();
    String connectionProtocol = findConnectionProtocol(databaseType, host, port, databaseName);
    Connection con = null;
    FileInputStream file = null;
    Statement st = null;
    try {
        Class.forName(getDbDriver(databaseType)).newInstance();
        file = new FileInputStream(basedir.getPath() + filePath + databaseType.toLowerCase() + File.separator
                + version + fileName);
        Scanner s = new Scanner(file);
        s.useDelimiter("(;(\r)?\n)|(--\n)");
        con = DriverManager.getConnection(connectionProtocol, userName, password);
        con.setAutoCommit(false);
        st = con.createStatement();
        while (s.hasNext()) {
            String line = s.next().trim();
            if (databaseType.equals("oracle")) {
                if (line.startsWith("--")) {
                    String comment = line.substring(line.indexOf("--"), line.lastIndexOf("--"));
                    line = line.replace(comment, "");
                    line = line.replace("--", "");
                }
                if (line.startsWith(Constants.REM_DELIMETER)) {
                    String comment = line.substring(0, line.lastIndexOf("\n"));
                    line = line.replace(comment, "");
                }
            }
            if (line.startsWith("/*!") && line.endsWith("*/")) {
                line = line.substring(line.indexOf("/*"), line.indexOf("*/") + 2);
            }
            if (line.trim().length() > 0) {
                st.execute(line);
            }
        }
    } catch (SQLException e) {
        throw new PhrescoException(e);
    } catch (FileNotFoundException e) {
        throw new PhrescoException(e);
    } catch (Exception e) {
        throw new PhrescoException(e);
    } finally {
        try {
            if (con != null) {
                con.commit();
                con.close();
            }
            if (file != null) {
                file.close();
            }
        } catch (Exception e) {
            throw new PhrescoException(e);
        }
    }
}

From source file:ru.histone.staticrender.StaticRender.java

public void renderSite(final Path srcDir, final Path dstDir) {
    log.info("Running StaticRender for srcDir={}, dstDir={}", srcDir.toString(), dstDir.toString());
    Path contentDir = srcDir.resolve("content/");
    final Path layoutDir = srcDir.resolve("layouts/");

    FileVisitor<Path> layoutVisitor = new SimpleFileVisitor<Path>() {
        @Override/*from ww  w. j  a  v  a 2s.c  o  m*/
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            if (file.toString().endsWith("." + TEMPLATE_FILE_EXTENSION)) {
                ArrayNode ast = null;
                try {
                    ast = histone.parseTemplateToAST(new FileReader(file.toFile()));
                } catch (HistoneException e) {
                    throw new RuntimeException("Error parsing histone template:" + e.getMessage(), e);
                }

                final String fileName = file.getFileName().toString();
                String layoutId = fileName.substring(0,
                        fileName.length() - TEMPLATE_FILE_EXTENSION.length() - 1);
                layouts.put(layoutId, ast);
                if (log.isDebugEnabled()) {
                    log.debug("Layout found id='{}', file={}", layoutId, file);
                } else {
                    log.info("Layout found id='{}'", layoutId);
                }
            } else {
                final Path relativeFileName = srcDir.resolve("layouts").relativize(Paths.get(file.toUri()));
                final Path resolvedFile = dstDir.resolve(relativeFileName);
                if (!resolvedFile.getParent().toFile().exists()) {
                    Files.createDirectories(resolvedFile.getParent());
                }
                Files.copy(Paths.get(file.toUri()), resolvedFile, StandardCopyOption.REPLACE_EXISTING,
                        LinkOption.NOFOLLOW_LINKS);
            }
            return FileVisitResult.CONTINUE;
        }
    };

    FileVisitor<Path> contentVisitor = new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {

            Scanner scanner = new Scanner(file, "UTF-8");
            scanner.useDelimiter("-----");

            String meta = null;
            StringBuilder content = new StringBuilder();

            if (!scanner.hasNext()) {
                throw new RuntimeException("Wrong format #1:" + file.toString());
            }

            if (scanner.hasNext()) {
                meta = scanner.next();
            }

            if (scanner.hasNext()) {
                content.append(scanner.next());
                scanner.useDelimiter("\n");
            }

            while (scanner.hasNext()) {
                final String next = scanner.next();
                content.append(next);

                if (scanner.hasNext()) {
                    content.append("\n");
                }
            }

            Map<String, String> metaYaml = (Map<String, String>) yaml.load(meta);

            String layoutId = metaYaml.get("layout");

            if (!layouts.containsKey(layoutId)) {
                throw new RuntimeException(MessageFormat.format("No layout with id='{0}' found", layoutId));
            }

            final Path relativeFileName = srcDir.resolve("content").relativize(Paths.get(file.toUri()));
            final Path resolvedFile = dstDir.resolve(relativeFileName);
            if (!resolvedFile.getParent().toFile().exists()) {
                Files.createDirectories(resolvedFile.getParent());
            }
            Writer output = new FileWriter(resolvedFile.toFile());
            ObjectNode context = jackson.createObjectNode();
            ObjectNode metaNode = jackson.createObjectNode();
            context.put("content", content.toString());
            context.put("meta", metaNode);
            for (String key : metaYaml.keySet()) {
                if (!key.equalsIgnoreCase("content")) {
                    metaNode.put(key, metaYaml.get(key));
                }
            }

            try {
                histone.evaluateAST(layoutDir.toUri().toString(), layouts.get(layoutId), context, output);
                output.flush();
            } catch (HistoneException e) {
                throw new RuntimeException("Error evaluating content: " + e.getMessage(), e);
            } finally {
                output.close();
            }

            return FileVisitResult.CONTINUE;
        }
    };

    try {
        Files.walkFileTree(layoutDir, layoutVisitor);
        Files.walkFileTree(contentDir, contentVisitor);
    } catch (Exception e) {
        throw new RuntimeException("Error during site render", e);
    }
}

From source file:org.orekit.files.ccsds.OEMParser.java

/**
 * Parse the covariance data lines, create a set of CovarianceMatrix objects
 * and add them in the covarianceMatrices list of the ephemerides block.
 *
 * @param reader the reader//from w  w  w  .  j  a  va2  s  .c  o m
 * @param pi the parser info
 * @throws IOException if an error occurs while reading from the stream
 * @throws OrekitException if the frame cannot be retrieved
 */
private void parseCovarianceDataLines(final BufferedReader reader, final ParseInfo pi)
        throws IOException, OrekitException {
    int i = 0;
    for (String line = reader.readLine(); line != null; line = reader.readLine()) {

        ++pi.lineNumber;
        if (line.trim().length() == 0) {
            continue;
        }
        pi.keyValue = new KeyValue(line, pi.lineNumber, pi.fileName);
        if (pi.keyValue.getKeyword() == null) {
            final Scanner sc = new Scanner(line);
            for (int j = 0; j < i + 1; j++) {
                try {
                    pi.lastMatrix.addToEntry(i, j, Double.parseDouble(sc.next()));
                } catch (NumberFormatException nfe) {
                    sc.close();
                    throw new OrekitException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, pi.lineNumber,
                            pi.fileName, line);
                }
                if (j != i) {
                    pi.lastMatrix.addToEntry(j, i, pi.lastMatrix.getEntry(i, j));
                }
            }
            if (i == 5) {
                final OEMFile.CovarianceMatrix cm = new OEMFile.CovarianceMatrix(pi.epoch, pi.covRefLofType,
                        pi.covRefFrame, pi.lastMatrix);
                pi.lastEphemeridesBlock.getCovarianceMatrices().add(cm);
            }
            i++;
            if (sc != null) {
                sc.close();
            }
        } else {
            switch (pi.keyValue.getKeyword()) {
            case EPOCH:
                i = 0;
                pi.covRefLofType = null;
                pi.covRefFrame = null;
                pi.lastMatrix = MatrixUtils.createRealMatrix(6, 6);
                pi.epoch = parseDate(pi.keyValue.getValue(),
                        pi.lastEphemeridesBlock.getMetaData().getTimeSystem());
                break;
            case COV_REF_FRAME:
                final CCSDSFrame frame = parseCCSDSFrame(pi.keyValue.getValue());
                if (frame.isLof()) {
                    pi.covRefLofType = frame.getLofType();
                    pi.covRefFrame = null;
                } else {
                    pi.covRefLofType = null;
                    pi.covRefFrame = frame.getFrame(getConventions(), isSimpleEOP());
                }
                break;
            case COVARIANCE_STOP:
                return;
            default:
                throw new OrekitException(OrekitMessages.CCSDS_UNEXPECTED_KEYWORD, pi.lineNumber, pi.fileName,
                        line);
            }
        }
    }
}

From source file:edu.harvard.iq.dataverse.dataaccess.TabularSubsetGenerator.java

public static String[] subsetStringVector(InputStream in, int column, int numCases) {
    String[] retVector = new String[numCases];
    Scanner scanner = new Scanner(in);
    scanner.useDelimiter("\\n");

    for (int caseIndex = 0; caseIndex < numCases; caseIndex++) {
        if (scanner.hasNext()) {
            String[] line = (scanner.next()).split("\t", -1);
            retVector[caseIndex] = line[column];

            if ("".equals(line[column])) {
                // An empty string is a string missing value!
                // An empty string in quotes is an empty string!
                retVector[caseIndex] = null;
            } else {
                // Strip the outer quotes:
                line[column] = line[column].replaceFirst("^\\\"", "");
                line[column] = line[column].replaceFirst("\\\"$", "");

                // We need to restore the special characters that 
                // are stored in tab files escaped - quotes, new lines 
                // and tabs. Before we do that however, we need to 
                // take care of any escaped backslashes stored in 
                // the tab file. I.e., "foo\t" should be transformed 
                // to "foo<TAB>"; but "foo\\t" should be transformed 
                // to "foo\t". This way new lines and tabs that were
                // already escaped in the original data are not 
                // going to be transformed to unescaped tab and 
                // new line characters!
                String[] splitTokens = line[column].split(Matcher.quoteReplacement("\\\\"), -2);

                // (note that it's important to use the 2-argument version 
                // of String.split(), and set the limit argument to a
                // negative value; otherwise any trailing backslashes 
                // are lost.)
                for (int i = 0; i < splitTokens.length; i++) {
                    splitTokens[i] = splitTokens[i].replaceAll(Matcher.quoteReplacement("\\\""), "\"");
                    splitTokens[i] = splitTokens[i].replaceAll(Matcher.quoteReplacement("\\t"), "\t");
                    splitTokens[i] = splitTokens[i].replaceAll(Matcher.quoteReplacement("\\n"), "\n");
                    splitTokens[i] = splitTokens[i].replaceAll(Matcher.quoteReplacement("\\r"), "\r");
                }/*from  w  w  w  .  jav a  2 s .  c o m*/
                // TODO: 
                // Make (some of?) the above optional; for ex., we 
                // do need to restore the newlines when calculating UNFs;
                // But if we are subsetting these vectors in order to 
                // create a new tab-delimited file, they will 
                // actually break things! -- L.A. Jul. 28 2014

                line[column] = StringUtils.join(splitTokens, '\\');

                retVector[caseIndex] = line[column];
            }

        } else {
            scanner.close();
            throw new RuntimeException("Tab file has fewer rows than the stored number of cases!");
        }
    }

    int tailIndex = numCases;
    while (scanner.hasNext()) {
        String nextLine = scanner.next();
        if (!"".equals(nextLine)) {
            scanner.close();
            throw new RuntimeException(
                    "Column " + column + ": tab file has more nonempty rows than the stored number of cases ("
                            + numCases + ")! current index: " + tailIndex + ", line: " + nextLine);
        }
        tailIndex++;
    }

    scanner.close();
    return retVector;

}

From source file:juicebox.windowui.QCDialog.java

public QCDialog(MainWindow mainWindow, HiC hic, String title) {
    super(mainWindow);

    Dataset dataset = hic.getDataset();// www. jav  a 2  s. com

    String text = dataset.getStatistics();
    String textDescription = null;
    String textStatistics = null;
    String graphs = dataset.getGraphs();
    JTextPane description = null;
    JTabbedPane tabbedPane = new JTabbedPane();
    HTMLEditorKit kit = new HTMLEditorKit();

    StyleSheet styleSheet = kit.getStyleSheet();
    styleSheet.addRule("table { border-collapse: collapse;}");
    styleSheet.addRule("body {font-family: Sans-Serif; font-size: 12;}");
    styleSheet.addRule("td { padding: 2px; }");
    styleSheet.addRule(
            "th {border-bottom: 1px solid #000; text-align: left; background-color: #D8D8D8; font-weight: normal;}");

    if (text != null) {
        int split = text.indexOf("</table>") + 8;
        textDescription = text.substring(0, split);
        textStatistics = text.substring(split);
        description = new JTextPane();
        description.setEditable(false);
        description.setContentType("text/html");
        description.setEditorKit(kit);
        description.setText(textDescription);
        tabbedPane.addTab("About Library", description);

        JTextPane textPane = new JTextPane();
        textPane.setEditable(false);
        textPane.setContentType("text/html");

        textPane.setEditorKit(kit);
        textPane.setText(textStatistics);
        JScrollPane pane = new JScrollPane(textPane);
        tabbedPane.addTab("Statistics", pane);
    }
    boolean success = true;
    if (graphs != null) {

        long[] A = new long[2000];
        long sumA = 0;
        long[] mapq1 = new long[201];
        long[] mapq2 = new long[201];
        long[] mapq3 = new long[201];
        long[] intraCount = new long[100];
        final XYSeries intra = new XYSeries("Intra Count");
        final XYSeries leftRead = new XYSeries("Left");
        final XYSeries rightRead = new XYSeries("Right");
        final XYSeries innerRead = new XYSeries("Inner");
        final XYSeries outerRead = new XYSeries("Outer");
        final XYSeries allMapq = new XYSeries("All MapQ");
        final XYSeries intraMapq = new XYSeries("Intra MapQ");
        final XYSeries interMapq = new XYSeries("Inter MapQ");

        Scanner scanner = new Scanner(graphs);
        try {
            while (!scanner.next().equals("["))
                ;

            for (int idx = 0; idx < 2000; idx++) {
                A[idx] = scanner.nextLong();
                sumA += A[idx];
            }

            while (!scanner.next().equals("["))
                ;
            for (int idx = 0; idx < 201; idx++) {
                mapq1[idx] = scanner.nextInt();
                mapq2[idx] = scanner.nextInt();
                mapq3[idx] = scanner.nextInt();

            }

            for (int idx = 199; idx >= 0; idx--) {
                mapq1[idx] = mapq1[idx] + mapq1[idx + 1];
                mapq2[idx] = mapq2[idx] + mapq2[idx + 1];
                mapq3[idx] = mapq3[idx] + mapq3[idx + 1];
                allMapq.add(idx, mapq1[idx]);
                intraMapq.add(idx, mapq2[idx]);
                interMapq.add(idx, mapq3[idx]);
            }
            while (!scanner.next().equals("["))
                ;
            for (int idx = 0; idx < 100; idx++) {
                int tmp = scanner.nextInt();
                if (tmp != 0)
                    innerRead.add(logXAxis[idx], tmp);
                intraCount[idx] = tmp;
                tmp = scanner.nextInt();
                if (tmp != 0)
                    outerRead.add(logXAxis[idx], tmp);
                intraCount[idx] += tmp;
                tmp = scanner.nextInt();
                if (tmp != 0)
                    rightRead.add(logXAxis[idx], tmp);
                intraCount[idx] += tmp;
                tmp = scanner.nextInt();
                if (tmp != 0)
                    leftRead.add(logXAxis[idx], tmp);
                intraCount[idx] += tmp;
                if (idx > 0)
                    intraCount[idx] += intraCount[idx - 1];
                if (intraCount[idx] != 0)
                    intra.add(logXAxis[idx], intraCount[idx]);
            }
        } catch (NoSuchElementException exception) {
            JOptionPane.showMessageDialog(getParent(), "Graphing file improperly formatted", "Error",
                    JOptionPane.ERROR_MESSAGE);
            success = false;
        }

        if (success) {
            final XYSeriesCollection readTypeCollection = new XYSeriesCollection();
            readTypeCollection.addSeries(innerRead);
            readTypeCollection.addSeries(outerRead);
            readTypeCollection.addSeries(leftRead);
            readTypeCollection.addSeries(rightRead);

            final JFreeChart readTypeChart = ChartFactory.createXYLineChart("Types of reads vs distance", // chart title
                    "Distance (log)", // domain axis label
                    "Binned Reads (log)", // range axis label
                    readTypeCollection, // data
                    PlotOrientation.VERTICAL, true, // include legend
                    true, false);

            final XYPlot readTypePlot = readTypeChart.getXYPlot();

            readTypePlot.setDomainAxis(new LogarithmicAxis("Distance (log)"));
            readTypePlot.setRangeAxis(new LogarithmicAxis("Binned Reads (log)"));
            readTypePlot.setBackgroundPaint(Color.white);
            readTypePlot.setRangeGridlinePaint(Color.lightGray);
            readTypePlot.setDomainGridlinePaint(Color.lightGray);
            readTypeChart.setBackgroundPaint(Color.white);
            readTypePlot.setOutlinePaint(Color.black);
            final ChartPanel chartPanel = new ChartPanel(readTypeChart);

            final XYSeriesCollection reCollection = new XYSeriesCollection();
            final XYSeries reDistance = new XYSeries("Distance");

            for (int i = 0; i < A.length; i++) {
                if (A[i] != 0)
                    reDistance.add(i, A[i] / (float) sumA);
            }
            reCollection.addSeries(reDistance);

            final JFreeChart reChart = ChartFactory.createXYLineChart(
                    "Distance from closest restriction enzyme site", // chart title
                    "Distance (bp)", // domain axis label
                    "Fraction of Reads (log)", // range axis label
                    reCollection, // data
                    PlotOrientation.VERTICAL, true, // include legend
                    true, false);

            final XYPlot rePlot = reChart.getXYPlot();
            rePlot.setDomainAxis(new NumberAxis("Distance (bp)"));
            rePlot.setRangeAxis(new LogarithmicAxis("Fraction of Reads (log)"));
            rePlot.setBackgroundPaint(Color.white);
            rePlot.setRangeGridlinePaint(Color.lightGray);
            rePlot.setDomainGridlinePaint(Color.lightGray);
            reChart.setBackgroundPaint(Color.white);
            rePlot.setOutlinePaint(Color.black);
            final ChartPanel chartPanel2 = new ChartPanel(reChart);

            final XYSeriesCollection intraCollection = new XYSeriesCollection();

            intraCollection.addSeries(intra);

            final JFreeChart intraChart = ChartFactory.createXYLineChart("Intra reads vs distance", // chart title
                    "Distance (log)", // domain axis label
                    "Cumulative Sum of Binned Reads (log)", // range axis label
                    intraCollection, // data
                    PlotOrientation.VERTICAL, true, // include legend
                    true, false);

            final XYPlot intraPlot = intraChart.getXYPlot();
            intraPlot.setDomainAxis(new LogarithmicAxis("Distance (log)"));
            intraPlot.setRangeAxis(new NumberAxis("Cumulative Sum of Binned Reads (log)"));
            intraPlot.setBackgroundPaint(Color.white);
            intraPlot.setRangeGridlinePaint(Color.lightGray);
            intraPlot.setDomainGridlinePaint(Color.lightGray);
            intraChart.setBackgroundPaint(Color.white);
            intraPlot.setOutlinePaint(Color.black);
            final ChartPanel chartPanel3 = new ChartPanel(intraChart);

            final XYSeriesCollection mapqCollection = new XYSeriesCollection();
            mapqCollection.addSeries(allMapq);
            mapqCollection.addSeries(intraMapq);
            mapqCollection.addSeries(interMapq);

            final JFreeChart mapqChart = ChartFactory.createXYLineChart("MapQ Threshold Count", // chart title
                    "MapQ threshold", // domain axis label
                    "Count", // range axis label
                    mapqCollection, // data
                    PlotOrientation.VERTICAL, true, // include legend
                    true, // include tooltips
                    false);

            final XYPlot mapqPlot = mapqChart.getXYPlot();
            mapqPlot.setBackgroundPaint(Color.white);
            mapqPlot.setRangeGridlinePaint(Color.lightGray);
            mapqPlot.setDomainGridlinePaint(Color.lightGray);
            mapqChart.setBackgroundPaint(Color.white);
            mapqPlot.setOutlinePaint(Color.black);
            final ChartPanel chartPanel4 = new ChartPanel(mapqChart);

            tabbedPane.addTab("Pair Type", chartPanel);
            tabbedPane.addTab("Restriction", chartPanel2);
            tabbedPane.addTab("Intra vs Distance", chartPanel3);
            tabbedPane.addTab("MapQ", chartPanel4);
        }
    }

    final ExpectedValueFunction df = hic.getDataset().getExpectedValues(hic.getZoom(),
            hic.getNormalizationType());
    if (df != null) {
        double[] expected = df.getExpectedValues();
        final XYSeriesCollection collection = new XYSeriesCollection();
        final XYSeries expectedValues = new XYSeries("Expected");
        for (int i = 0; i < expected.length; i++) {
            if (expected[i] > 0)
                expectedValues.add(i + 1, expected[i]);
        }
        collection.addSeries(expectedValues);
        String title1 = "Expected at " + hic.getZoom() + " norm " + hic.getNormalizationType();
        final JFreeChart readTypeChart = ChartFactory.createXYLineChart(title1, // chart title
                "Distance between reads (log)", // domain axis label
                "Genome-wide expected (log)", // range axis label
                collection, // data
                PlotOrientation.VERTICAL, false, // include legend
                true, false);
        final XYPlot readTypePlot = readTypeChart.getXYPlot();

        readTypePlot.setDomainAxis(new LogarithmicAxis("Distance between reads (log)"));
        readTypePlot.setRangeAxis(new LogarithmicAxis("Genome-wide expected (log)"));
        readTypePlot.setBackgroundPaint(Color.white);
        readTypePlot.setRangeGridlinePaint(Color.lightGray);
        readTypePlot.setDomainGridlinePaint(Color.lightGray);
        readTypeChart.setBackgroundPaint(Color.white);
        readTypePlot.setOutlinePaint(Color.black);
        final ChartPanel chartPanel5 = new ChartPanel(readTypeChart);

        tabbedPane.addTab("Expected", chartPanel5);
    }

    if (text == null && graphs == null) {
        JOptionPane.showMessageDialog(this, "Sorry, no metrics are available for this dataset", "Error",
                JOptionPane.ERROR_MESSAGE);
        setVisible(false);
        dispose();

    } else {
        getContentPane().add(tabbedPane);
        pack();
        setModal(false);
        setLocation(100, 100);
        setTitle(title);
        setVisible(true);
    }
}

From source file:in.rab.ordboken.NeClient.java

private String inputStreamToString(InputStream input) throws IOException {
    Scanner scanner = new Scanner(input).useDelimiter("\\A");
    String str = scanner.hasNext() ? scanner.next() : "";

    input.close();//from w w w .j av  a 2 s.  c om

    return str;
}