Search in sources :

Example 21 with LineNumberReader

use of java.io.LineNumberReader in project voltdb by VoltDB.

the class LobManager method createSchema.

public void createSchema() {
    sysLobSession = database.sessionManager.getSysLobSession();
    Session session = sysLobSession;
    InputStream fis = getClass().getResourceAsStream(resourceFileName);
    InputStreamReader reader = null;
    try {
        reader = new InputStreamReader(fis, "ISO-8859-1");
    } catch (Exception e) {
    }
    LineNumberReader lineReader = new LineNumberReader(reader);
    LineGroupReader lg = new LineGroupReader(lineReader, starters);
    HashMappedList map = lg.getAsMap();
    lg.close();
    String sql = (String) map.get("/*lob_schema_definition*/");
    Statement statement = session.compileStatement(sql);
    Result result = statement.execute(session);
    Table table = database.schemaManager.getTable(session, "BLOCKS", "SYSTEM_LOBS");
    //            table.isTransactional = false;
    getLob = session.compileStatement(getLobSQL);
    getLobPart = session.compileStatement(getLobPartSQL);
    createLob = session.compileStatement(createLobSQL);
    createLobPart = session.compileStatement(createLobPartSQL);
    divideLobPart = session.compileStatement(divideLobPartSQL);
    deleteLob = session.compileStatement(deleteLobSQL);
    deleteLobPart = session.compileStatement(deleteLobPartSQL);
    setLobLength = session.compileStatement(updateLobLengthSQL);
    setLobUsage = session.compileStatement(updateLobUsageSQL);
    getNextLobId = session.compileStatement(getNextLobIdSQL);
}
Also used : HashMappedList(org.hsqldb_voltpatches.lib.HashMappedList) Table(org.hsqldb_voltpatches.Table) InputStreamReader(java.io.InputStreamReader) LineGroupReader(org.hsqldb_voltpatches.lib.LineGroupReader) HsqlByteArrayInputStream(org.hsqldb_voltpatches.lib.HsqlByteArrayInputStream) InputStream(java.io.InputStream) Statement(org.hsqldb_voltpatches.Statement) IOException(java.io.IOException) EOFException(java.io.EOFException) HsqlException(org.hsqldb_voltpatches.HsqlException) Session(org.hsqldb_voltpatches.Session) LineNumberReader(java.io.LineNumberReader) Result(org.hsqldb_voltpatches.result.Result)

Example 22 with LineNumberReader

use of java.io.LineNumberReader in project jdk8u_jdk by JetBrains.

the class Lines method testPartialReadAndLineNo.

public void testPartialReadAndLineNo() throws IOException {
    MockLineReader r = new MockLineReader(5);
    LineNumberReader lr = new LineNumberReader(r);
    char[] buf = new char[5];
    lr.read(buf, 0, 5);
    assertEquals(0, lr.getLineNumber(), "LineNumberReader start with line 0");
    assertEquals(1, r.getLineNumber(), "MockLineReader start with line 1");
    assertEquals(new String(buf), "Line ");
    String l1 = lr.readLine();
    assertEquals(l1, "1", "Remaining of the first line");
    assertEquals(1, lr.getLineNumber(), "Line 1 is read");
    assertEquals(1, r.getLineNumber(), "MockLineReader not yet go next line");
    lr.read(buf, 0, 4);
    assertEquals(1, lr.getLineNumber(), "In the middle of line 2");
    assertEquals(new String(buf, 0, 4), "Line");
    ArrayList<String> ar = lr.lines().peek(l -> assertEquals(lr.getLineNumber(), r.getLineNumber())).collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
    assertEquals(ar.get(0), " 2", "Remaining in the second line");
    for (int i = 1; i < ar.size(); i++) {
        assertEquals(ar.get(i), "Line " + (i + 2), "Rest are full lines");
    }
}
Also used : Iterator(java.util.Iterator) LineNumberReader(java.io.LineNumberReader) IOException(java.io.IOException) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) Reader(java.io.Reader) ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) Stream(java.util.stream.Stream) StringReader(java.io.StringReader) Assert(org.testng.Assert) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) BufferedReader(java.io.BufferedReader) NoSuchElementException(java.util.NoSuchElementException) Spliterator(java.util.Spliterator) ArrayList(java.util.ArrayList) LineNumberReader(java.io.LineNumberReader)

Example 23 with LineNumberReader

use of java.io.LineNumberReader in project OpenRefine by OpenRefine.

the class SeparatorBasedImporter method parseOneFile.

@Override
public void parseOneFile(Project project, ProjectMetadata metadata, ImportingJob job, String fileSource, Reader reader, int limit, JSONObject options, List<Exception> exceptions) {
    String sep = JSONUtilities.getString(options, "separator", "\\t");
    if (sep == null || "".equals(sep)) {
        sep = "\\t";
    }
    sep = StringEscapeUtils.unescapeJava(sep);
    boolean processQuotes = JSONUtilities.getBoolean(options, "processQuotes", true);
    boolean strictQuotes = JSONUtilities.getBoolean(options, "strictQuotes", false);
    final CSVParser parser = new CSVParser(sep, CSVParser.DEFAULT_QUOTE_CHARACTER, // we don't want escape processing
    (char) 0, strictQuotes, CSVParser.DEFAULT_IGNORE_LEADING_WHITESPACE, !processQuotes);
    final LineNumberReader lnReader = new LineNumberReader(reader);
    TableDataReader dataReader = new TableDataReader() {

        @Override
        public List<Object> getNextRowOfCells() throws IOException {
            String line = lnReader.readLine();
            if (line == null) {
                return null;
            } else {
                return getCells(line, parser, lnReader);
            }
        }
    };
    TabularImportingParserBase.readTable(project, metadata, job, dataReader, fileSource, limit, options, exceptions);
}
Also used : CSVParser(au.com.bytecode.opencsv.CSVParser) JSONObject(org.json.JSONObject) LineNumberReader(java.io.LineNumberReader)

Example 24 with LineNumberReader

use of java.io.LineNumberReader in project lucene-solr by apache.

the class UnknownDictionaryBuilder method readCharacterDefinition.

public void readCharacterDefinition(String filename, UnknownDictionaryWriter dictionary) throws IOException {
    FileInputStream inputStream = new FileInputStream(filename);
    InputStreamReader streamReader = new InputStreamReader(inputStream, encoding);
    LineNumberReader lineReader = new LineNumberReader(streamReader);
    String line = null;
    while ((line = lineReader.readLine()) != null) {
        line = line.replaceAll("^\\s", "");
        line = line.replaceAll("\\s*#.*", "");
        line = line.replaceAll("\\s+", " ");
        // Skip empty line or comment line
        if (line.length() == 0) {
            continue;
        }
        if (line.startsWith("0x")) {
            // Category mapping
            // Split only first space
            String[] values = line.split(" ", 2);
            if (!values[0].contains("..")) {
                int cp = Integer.decode(values[0]).intValue();
                dictionary.putCharacterCategory(cp, values[1]);
            } else {
                String[] codePoints = values[0].split("\\.\\.");
                int cpFrom = Integer.decode(codePoints[0]).intValue();
                int cpTo = Integer.decode(codePoints[1]).intValue();
                for (int i = cpFrom; i <= cpTo; i++) {
                    dictionary.putCharacterCategory(i, values[1]);
                }
            }
        } else {
            // Invoke definition
            // Consecutive space is merged above
            String[] values = line.split(" ");
            String characterClassName = values[0];
            int invoke = Integer.parseInt(values[1]);
            int group = Integer.parseInt(values[2]);
            int length = Integer.parseInt(values[3]);
            dictionary.putInvokeDefinition(characterClassName, invoke, group, length);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) LineNumberReader(java.io.LineNumberReader)

Example 25 with LineNumberReader

use of java.io.LineNumberReader in project lucene-solr by apache.

the class TestSearchMode method testSearchSegmentation.

/** Test search mode segmentation */
public void testSearchSegmentation() throws IOException {
    InputStream is = TestSearchMode.class.getResourceAsStream(SEGMENTATION_FILENAME);
    if (is == null) {
        throw new FileNotFoundException("Cannot find " + SEGMENTATION_FILENAME + " in test classpath");
    }
    try {
        LineNumberReader reader = new LineNumberReader(new InputStreamReader(is, StandardCharsets.UTF_8));
        String line = null;
        while ((line = reader.readLine()) != null) {
            // Remove comments
            line = line.replaceAll("#.*$", "");
            // Skip empty lines or comment lines
            if (line.trim().isEmpty()) {
                continue;
            }
            if (VERBOSE) {
                System.out.println("Line no. " + reader.getLineNumber() + ": " + line);
            }
            String[] fields = line.split("\t", 2);
            String sourceText = fields[0];
            String[] expectedTokens = fields[1].split("\\s+");
            int[] expectedPosIncrs = new int[expectedTokens.length];
            int[] expectedPosLengths = new int[expectedTokens.length];
            for (int tokIDX = 0; tokIDX < expectedTokens.length; tokIDX++) {
                if (expectedTokens[tokIDX].endsWith("/0")) {
                    expectedTokens[tokIDX] = expectedTokens[tokIDX].replace("/0", "");
                    expectedPosLengths[tokIDX] = expectedTokens.length - 1;
                } else {
                    expectedPosIncrs[tokIDX] = 1;
                    expectedPosLengths[tokIDX] = 1;
                }
            }
            assertAnalyzesTo(analyzer, sourceText, expectedTokens, expectedPosIncrs);
        }
    } finally {
        is.close();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) LineNumberReader(java.io.LineNumberReader)

Aggregations

LineNumberReader (java.io.LineNumberReader)401 IOException (java.io.IOException)203 InputStreamReader (java.io.InputStreamReader)167 FileReader (java.io.FileReader)102 File (java.io.File)79 InputStream (java.io.InputStream)64 StringReader (java.io.StringReader)64 ArrayList (java.util.ArrayList)54 FileInputStream (java.io.FileInputStream)33 BufferedReader (java.io.BufferedReader)27 PrintWriter (java.io.PrintWriter)25 HashMap (java.util.HashMap)22 FileNotFoundException (java.io.FileNotFoundException)20 BufferedWriter (java.io.BufferedWriter)16 FileWriter (java.io.FileWriter)16 Pattern (java.util.regex.Pattern)16 Test (org.junit.jupiter.api.Test)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 Reader (java.io.Reader)14