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);
}
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");
}
}
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);
}
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);
}
}
}
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();
}
}
Aggregations