本文整理汇总了Java中java.io.LineNumberReader.getLineNumber方法的典型用法代码示例。如果您正苦于以下问题:Java LineNumberReader.getLineNumber方法的具体用法?Java LineNumberReader.getLineNumber怎么用?Java LineNumberReader.getLineNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.LineNumberReader
的用法示例。
在下文中一共展示了LineNumberReader.getLineNumber方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseConversions
import java.io.LineNumberReader; //导入方法依赖的package包/类
private FST<CharsRef> parseConversions(LineNumberReader reader, int num) throws IOException, ParseException {
Map<String,String> mappings = new TreeMap<>();
for (int i = 0; i < num; i++) {
String line = reader.readLine();
String parts[] = line.split("\\s+");
if (parts.length != 3) {
throw new ParseException("invalid syntax: " + line, reader.getLineNumber());
}
if (mappings.put(parts[1], parts[2]) != null) {
throw new IllegalStateException("duplicate mapping specified for: " + parts[1]);
}
}
Outputs<CharsRef> outputs = CharSequenceOutputs.getSingleton();
Builder<CharsRef> builder = new Builder<>(FST.INPUT_TYPE.BYTE2, outputs);
IntsRefBuilder scratchInts = new IntsRefBuilder();
for (Map.Entry<String,String> entry : mappings.entrySet()) {
Util.toUTF16(entry.getKey(), scratchInts);
builder.add(scratchInts.get(), new CharsRef(entry.getValue()));
}
return builder.finish();
}
示例2: parseDataStartTimeFromAeDatFile
import java.io.LineNumberReader; //导入方法依赖的package包/类
private long parseDataStartTimeFromAeDatFile(AEFileInputStream aeis) throws FileNotFoundException, IOException {
// # DataStartTime: System.currentTimeMillis() 1481800498468
File f = aeis.getFile();
LineNumberReader is = new LineNumberReader(new InputStreamReader(new FileInputStream(f)));
while (is.getLineNumber() < 5000) {
String line = is.readLine();
if (line.contains("DataStartTime")) {
Scanner s = new Scanner(line);
s.next();
s.next();
s.next();
aeDatStartTimeMs = s.nextLong();
return aeDatStartTimeMs;
}
}
log.warning("could not find data start time DataStartTime in AEDAT file");
return -1;
}
示例3: loadOptions
import java.io.LineNumberReader; //导入方法依赖的package包/类
public static String loadOptions(FileReader fr, String filename) {
LineNumberReader lnr = new LineNumberReader(fr);
Group.restoreAllDefaults();
String line;
try {
while ((line = lnr.readLine()) != null) {
String reason = Group.root.setOption(line);
if (reason != null) {
System.err.println("Option "+line+
" at line "+lnr.getLineNumber()+
" ignored: "+reason);
}
}
} catch (IOException e) {
Group.restoreAllDefaults();
return ("IO Error reading "+filename+
" at line "+lnr.getLineNumber());
}
return null;
}
示例4: countDataPJson
import java.io.LineNumberReader; //导入方法依赖的package包/类
/**
* Count and return data pjson line.
* @return Total line number
*/
public long countDataPJson() {
Path pathInZip = pathMap.get(DATA_PJSON);
try (BufferedReader bufReader = Files.newBufferedReader(pathInZip, Charsets.UTF_8)) {
LineNumberReader reader = new LineNumberReader(bufReader);
while (true) {
long readByte = reader.skip(SKIP_DATA_NUM);
if (readByte == 0) {
break;
}
}
return reader.getLineNumber();
} catch (IOException e) {
throw PersoniumCoreException.Common.FILE_IO_ERROR.params("read data pjson from snapshot file").reason(e);
}
}
示例5: getNextStatement
import java.io.LineNumberReader; //导入方法依赖的package包/类
DDLStatement getNextStatement(LineNumberReader reader, VoltCompiler compiler) throws VoltCompiler.VoltCompilerException {
DDLStatement retval = new DDLStatement();
try {
String stmt = "";
// skip over any empty lines to read first real line
while (stmt.equals("") || stmt.startsWith("--")) {
stmt = reader.readLine();
if (stmt == null)
return null;
stmt = stmt.trim();
}
// record the line number
retval.lineNo = reader.getLineNumber();
// add all lines until one ends with a semicolon
while ((stmt.endsWith(";") == false) && (stmt.endsWith(";\n") == false)) {
String newline = reader.readLine();
if (newline == null) {
String msg = "Schema file ended mid statment (no semicolon found)";
throw compiler.new VoltCompilerException(msg, retval.lineNo);
}
newline = newline.trim();
if (newline.equals(""))
continue;
if (newline.startsWith("--"))
continue;
stmt += newline + "\n";
}
retval.statement = stmt;
} catch (IOException e) {
throw compiler.new VoltCompilerException("Unable to read from file");
}
return retval;
}
示例6: countLines
import java.io.LineNumberReader; //导入方法依赖的package包/类
public static long countLines(String filePath) throws Exception {
LineNumberReader lnr = new LineNumberReader(new FileReader(new File(filePath)));
try {
lnr.skip(Long.MAX_VALUE);
return lnr.getLineNumber() + 1;
} finally {
lnr.close();
}
}
示例7: countLines
import java.io.LineNumberReader; //导入方法依赖的package包/类
public static long countLines(String filePath) throws Exception {
LineNumberReader lnr = new LineNumberReader(new FileReader(new File(filePath)));
try {
lnr.skip(Long.MAX_VALUE);
return lnr.getLineNumber() + 1;
} finally {
lnr.close();
}
}
示例8: countLines
import java.io.LineNumberReader; //导入方法依赖的package包/类
public static int countLines(File f) throws FileNotFoundException{
int result = -1;
LineNumberReader lnr = new LineNumberReader(new FileReader(f));
try {
lnr.skip(Long.MAX_VALUE);
result = lnr.getLineNumber() + 1; //Add 1 because line index starts at 0
// Finally, the LineNumberReader object should be closed to prevent resource leak
lnr.close();
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage());
}
return result;
}
示例9: parse
import java.io.LineNumberReader; //导入方法依赖的package包/类
@Override
public void parse(Reader in) throws IOException, ParseException {
LineNumberReader br = new LineNumberReader(in);
try {
String line = null;
String lastSynSetID = "";
CharsRef synset[] = new CharsRef[8];
int synsetSize = 0;
while ((line = br.readLine()) != null) {
String synSetID = line.substring(2, 11);
if (!synSetID.equals(lastSynSetID)) {
addInternal(synset, synsetSize);
synsetSize = 0;
}
if (synset.length <= synsetSize+1) {
synset = Arrays.copyOf(synset, synset.length * 2);
}
synset[synsetSize] = parseSynonym(line, new CharsRefBuilder());
synsetSize++;
lastSynSetID = synSetID;
}
// final synset in the file
addInternal(synset, synsetSize);
} catch (IllegalArgumentException e) {
ParseException ex = new ParseException("Invalid synonym rule at line " + br.getLineNumber(), 0);
ex.initCause(e);
throw ex;
} finally {
br.close();
}
}
示例10: parse
import java.io.LineNumberReader; //导入方法依赖的package包/类
@Override
public void parse(Reader in) throws IOException, ParseException {
LineNumberReader br = new LineNumberReader(in);
try {
addInternal(br);
} catch (IllegalArgumentException e) {
ParseException ex = new ParseException("Invalid synonym rule at line " + br.getLineNumber(), 0);
ex.initCause(e);
throw ex;
} finally {
br.close();
}
}
示例11: parseRules
import java.io.LineNumberReader; //导入方法依赖的package包/类
private static Rule[] parseRules(LineNumberReader r, int type) throws IOException {
List<Rule> rules = new ArrayList<>();
String line;
while ((line = readLine(r)) != null) {
Matcher matcher = stripPattern.matcher(line);
if (matcher.matches()) {
rules.add(new Rule(matcher.group(1), Integer.parseInt(matcher.group(2)), ""));
} else {
matcher = repPattern.matcher(line);
if (matcher.matches()) {
rules.add(new Rule(matcher.group(1), Integer.parseInt(matcher.group(2)), matcher.group(3)));
} else {
matcher = excPattern.matcher(line);
if (matcher.matches()) {
if (type == 0) {
rules.add(new RuleWithSuffixExceptions(matcher.group(1),
Integer.parseInt(matcher.group(2)),
matcher.group(3),
parseList(matcher.group(4))));
} else {
rules.add(new RuleWithSetExceptions(matcher.group(1),
Integer.parseInt(matcher.group(2)),
matcher.group(3),
parseList(matcher.group(4))));
}
} else {
throw new RuntimeException("Illegal Step rule specified at line " + r.getLineNumber());
}
}
}
if (line.endsWith(";"))
return rules.toArray(new Rule[rules.size()]);
}
return null;
}
示例12: leesRegel
import java.io.LineNumberReader; //导入方法依赖的package包/类
private String leesRegel(LineNumberReader br, int regelnummer) {
try {
String regel = null;
while (br.getLineNumber() <= regelnummer) {
regel = br.readLine();
}
return regel;
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
示例13: readMultiLineComment
import java.io.LineNumberReader; //导入方法依赖的package包/类
private static String readMultiLineComment(final InputStream is, final int lineNum,
final Function<String, String> stripLine) throws IOException {
final LineNumberReader reader = new LineNumberReader(new InputStreamReader(is));
final StringBuilder buff = new StringBuilder();
String line = reader.readLine();
// moving to the target line of the stack
for (; line != null; line = reader.readLine()) {
if (reader.getLineNumber() >= lineNum) {
break;
}
}
// getting the first line of the comment
for (; line != null; line = reader.readLine()) {
final int endOfMethodIdx = line.indexOf(");");
final int startCommentIdx = line.indexOf(START_COMMENT);
if (startCommentIdx == -1 && endOfMethodIdx <= startCommentIdx) {
throw new RuntimeException("String definition not found");
}
if (startCommentIdx >= 0) {
// removing what is out of the comment
line = line.substring(startCommentIdx + 2, line.length());
if (line.startsWith(END_COMMENT)) {
return ""; // comment opened and immediately closed
}
if (line.startsWith("*")) {
line = line.substring(1);
}
break;
}
}
// continue until the end of the comment
for (; line != null; line = reader.readLine()) {
line = stripLine.apply(line);
final int idx = line.indexOf(END_COMMENT);
if (idx >= 0) {
// removing what is out of the comment
buff.append(line.substring(0, idx));
break;
}
buff.append(line);
buff.append('\n');
}
return buff.toString();
}
示例14: create
import java.io.LineNumberReader; //导入方法依赖的package包/类
public static ClassAndMethodDetails create(LineNumberReader in) throws IOException {
String line;
while ((line = in.readLine()) != null) {
line = line.trim();
if (line.length() == 0 || line.startsWith("#") || line.startsWith("//")) {
continue;
}
break;
}
if (line == null) {
return null;
}
ClassAndMethodDetails instance = new ClassAndMethodDetails();
String[] fields = line.split(",");
try {
instance.className = fields[0];
int numMethods = Integer.parseInt(fields[1]);
for (int i = 0; i < numMethods; i++) {
line = in.readLine();
fields = line.split(",");
String methodName = fields[0];
int codeLength = Integer.parseInt(fields[1]);
String codeString = fields[2].trim();
int codeStringLength = codeString.length();
if (codeStringLength != codeLength * 2) {
System.err.println("Code string has been tampered with on line " + in.getLineNumber());
continue;
}
byte[] code = new byte[codeLength];
int codeIdx = 0;
for (int j = 0; j < codeStringLength; j += 2) {
String substr = codeString.substring(j, j + 2);
// System.out.println("parsing " + j + ": '" + substr + "'");
code[codeIdx++] = (byte) (0xff & Integer.parseInt(substr, 16));
}
instance.methodCode.put(methodName, code);
}
return instance;
} catch (Exception e) {
throw new IOException("Error parsing line " + in.getLineNumber(), e);
}
}