Java URL Load readLinesTrimmedNoCommentFromUrl(final URL fileUrl, final String commentString)

Here you can find the source of readLinesTrimmedNoCommentFromUrl(final URL fileUrl, final String commentString)

Description

read Lines Trimmed No Comment From Url

License

Apache License

Declaration

public static String[] readLinesTrimmedNoCommentFromUrl(final URL fileUrl, final String commentString)
            throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;

public class Main {
    public static String[] readLinesTrimmedNoCommentFromUrl(final URL fileUrl, final String commentString)
            throws IOException {
        BufferedReader in = null;
        try {/*from  ww w.j a  v a  2 s . c  o m*/
            in = new BufferedReader(new InputStreamReader(fileUrl.openStream()));
        } catch (IOException e) {
            throw new IOException("IOException during reading from URL: \"" + fileUrl + "\"");
        }

        return readLinesTrimmedNoCommmentFromBufferedReader(in, commentString);
    }

    private static String[] readLinesTrimmedNoCommmentFromBufferedReader(final BufferedReader in,
            final String commentString) throws IOException {
        ArrayList<String> lineList = new ArrayList<String>();
        String line;
        while (in.ready()) {
            line = in.readLine();
            if (line == null) {
                continue;
            }

            line = line.trim();

            if (line.startsWith(commentString))
                continue;

            if (line.contains(commentString)) {
                String[] items = line.split(commentString);
                line = items[0].trim();
            }

            lineList.add(line);
        }

        in.close();

        String[] lines = new String[lineList.size()];

        lineList.toArray(lines);

        return lines;
    }
}

Related

  1. readInteger(URL src, int radix)
  2. readJsonFromUrl(String urlString)
  3. readLines(final String url)
  4. readLines(final URL url)
  5. readLines(URL url)
  6. readListFile(URL listFile)
  7. readListFile(URL listFile)
  8. readMappingFile(final URL filename)
  9. readModelFromUrl(URL file, Class clazz)