java.io.LineNumberReader Java Examples
The following examples show how to use
java.io.LineNumberReader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DBScriptUtil.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Read a script from the provided LineNumberReader, using the supplied line * comment prefix, and build a String containing the lines. * * @param lineNumberReader * the LineNumberReader containing the script to be processed * @param lineCommentPrefix * the prefix that identifies comments in the SQL script (typically * "--") * @return a String containing the script lines */ private static String readScript(LineNumberReader lineNumberReader, String lineCommentPrefix) throws IOException { String statement = lineNumberReader.readLine(); StringBuilder scriptBuilder = new StringBuilder(); while (statement != null) { if (lineCommentPrefix != null && !statement.startsWith(lineCommentPrefix)) { if (scriptBuilder.length() > 0) { scriptBuilder.append('\n'); } scriptBuilder.append(statement); } statement = lineNumberReader.readLine(); } return scriptBuilder.toString(); }
Example #2
Source File: IrTransImporter.java From IrScrutinizer with GNU General Public License v3.0 | 6 votes |
private Map<String, IrTransCommand> parseCommands(LineNumberReader reader, List<Timing> timings) throws IOException, ParseException { gobbleTo(reader, "[COMMANDS]", true); Map<String, IrTransCommand> commands = new LinkedHashMap<>(32); while (true) { String line = reader.readLine(); if (line == null || line.trim().isEmpty()) break; try { IrTransCommand command = parseCommand(line, timings, reader.getLineNumber()); commands.put(command.name, command); } catch (ParseException | NumberFormatException ex) { // just ignore unparsable command, go on reading System.err.println("Command " + line + " (line " + reader.getLineNumber() + ") did not parse, ignored. " + ex.getLocalizedMessage()); } } return commands; }
Example #3
Source File: MarkSplitCRLF.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test public static void testSpecifiedBufferSize() throws IOException { final String string = "foo\r\nbar"; try (Reader reader = new LineNumberReader(new StringReader(string), 5)) { reader.read(); // 'f' reader.read(); // 'o' reader.read(); // 'o' reader.read(); // '\r' -> '\n' reader.mark(1); // mark position of '\n' reader.read(); // 'b' reader.reset(); // reset to '\n' position assertEquals(reader.read(), 'b'); assertEquals(reader.read(), 'a'); assertEquals(reader.read(), 'r'); } }
Example #4
Source File: MarkSplitCRLF.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@Test public static void testCRNotFollowedByLF() throws IOException { final String string = "foo\rbar"; try (Reader reader = new LineNumberReader(new StringReader(string), 5)) { reader.read(); // 'f' reader.read(); // 'o' reader.read(); // 'o' reader.read(); // '\r' reader.mark(1); // mark position of next character reader.read(); // 'b' reader.reset(); // reset to position after '\r' assertEquals(reader.read(), 'b'); assertEquals(reader.read(), 'a'); assertEquals(reader.read(), 'r'); } }
Example #5
Source File: IrTransImporter.java From IrScrutinizer with GNU General Public License v3.0 | 6 votes |
private Remote parseRemote(LineNumberReader reader) throws IOException, ParseException { String name = parseName(reader); if (name == null) return null; // EOF List<Timing> timings = parseTimings(reader); Map<String, IrTransCommand> parsedCommands = parseCommands(reader, timings); if (parsedCommands.isEmpty()) throw new ParseException("Remote had no parsable commands.", 0); Map<String, Command> commands = new LinkedHashMap<>(4); parsedCommands.values().forEach((cmd) -> { try { Command command = cmd.toCommand(); commands.put(command.getName(), command); } catch (GirrException | InvalidArgumentException ex) { System.err.println(cmd.name + " Unparsable signal: " + ex.getMessage()); } }); return new Remote(new Remote.MetaData(name), null, null, commands, null); }
Example #6
Source File: Evaluator.java From bluima with Apache License 2.0 | 6 votes |
protected List readRef(File f) throws IOException { List list = new ArrayList(); LineNumberReader lr = new LineNumberReader(new FileReader(f)); String line = null; while ((line = lr.readLine()) != null) { String[] s = line.split("\t"); if (s[0].equals("0")) list.add(new Double("-1")); else if (s[0].equals("1")) list.add(new Double("1")); } return list; }
Example #7
Source File: TestBigFileRead.java From basic-tools with MIT License | 6 votes |
public static long getLineNumber(File file) { if (file.exists()) { try { FileReader fileReader = new FileReader(file); LineNumberReader lineNumberReader = new LineNumberReader(fileReader); lineNumberReader.skip(Long.MAX_VALUE); long lines = lineNumberReader.getLineNumber() + 1; fileReader.close(); lineNumberReader.close(); return lines; } catch (IOException e) { e.printStackTrace(); } } return 0; }
Example #8
Source File: SerialPortFinder.java From Android-SerialPort-API with Apache License 2.0 | 6 votes |
Vector<Driver> getDrivers() throws IOException { if (mDrivers == null) { mDrivers = new Vector<Driver>(); LineNumberReader r = new LineNumberReader(new FileReader("/proc/tty/drivers")); String l; while ((l = r.readLine()) != null) { // Issue 3: // Since driver name may contain spaces, we do not extract driver name with split() String drivername = l.substring(0, 0x15).trim(); String[] w = l.split(" +"); if ((w.length >= 5) && (w[w.length - 1].equals("serial"))) { Log.d(TAG, "Found new driver " + drivername + " on " + w[w.length - 4]); mDrivers.add(new Driver(drivername, w[w.length - 4])); } } r.close(); } return mDrivers; }
Example #9
Source File: DependencyBnBPreorderer.java From phrasal with GNU General Public License v3.0 | 6 votes |
private static Set<String> getMostFrequentTokens(LineNumberReader reader, int k) throws IOException { Counter<String> tokenCounts = new ClassicCounter<String>(); String line; while ((line = reader.readLine()) != null) { String tokens[] = line.split("\\s+"); for (String t : tokens) { tokenCounts.incrementCount(t); } } Set<String> mostFrequentTokens = new HashSet<>(k); Counters.retainTop(tokenCounts, k); mostFrequentTokens.addAll(tokenCounts.keySet()); tokenCounts = null; return mostFrequentTokens; }
Example #10
Source File: Lines.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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"); } }
Example #11
Source File: Lines.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
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"); } }
Example #12
Source File: J2DBench.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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; }
Example #13
Source File: MarkSplitCRLF.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test public static void testCRNotFollowedByLF() throws IOException { final String string = "foo\rbar"; try (Reader reader = new LineNumberReader(new StringReader(string), 5)) { reader.read(); // 'f' reader.read(); // 'o' reader.read(); // 'o' reader.read(); // '\r' reader.mark(1); // mark position of next character reader.read(); // 'b' reader.reset(); // reset to position after '\r' assertEquals(reader.read(), 'b'); assertEquals(reader.read(), 'a'); assertEquals(reader.read(), 'r'); } }
Example #14
Source File: MarkSplitCRLF.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test public static void testDefaultBufferSize() throws IOException { StringBuilder sb = new StringBuilder(8195); for (int i = 0; i < 8190; i++) { char c = (char)i; sb.append(c); } sb.append('\r'); sb.append('\n'); sb.append('X'); sb.append('Y'); sb.append('Z'); final String string = sb.toString(); try (Reader reader = new LineNumberReader(new StringReader(string))) { for (int i = 0; i < 8191; i++) reader.read(); reader.mark(1); reader.read(); reader.reset(); assertEquals(reader.read(), 'X'); assertEquals(reader.read(), 'Y'); assertEquals(reader.read(), 'Z'); } }
Example #15
Source File: PemUtil.java From keystore-explorer with GNU General Public License v3.0 | 6 votes |
private static String skipOverEcParams(LineNumberReader lnr) throws IOException { String line = lnr.readLine(); // skip over EC parameter block if (line != null && OPENSSL_EC_PARAMS_PEM_TYPE.equals(getTypeFromHeader(line.trim()))) { // now find end line while( (line = lnr.readLine()) != null ) { line = line.trim(); if (OPENSSL_EC_PARAMS_PEM_TYPE.equals(getTypeFromFooter(line))) { line = lnr.readLine(); break; } } } return line; }
Example #16
Source File: ApproximateRandomizationProcedure.java From bluima with Apache License 2.0 | 6 votes |
private void read(File ans, File ref) throws IOException { LineNumberReader ar = new LineNumberReader(new FileReader(ans)); LineNumberReader rr = new LineNumberReader(new FileReader(ref)); String a = null, r = null; while (((a = ar.readLine()) != null) && ((r = rr.readLine()) != null)) { // logger.debug("a: " + a); // logger.debug("r: " + r); String[] s = r.split("\t"); // logger.debug("s[1]: " + s[1]); String id = s[1].substring(0, s[1].indexOf('-')); // logger.debug("id: " + id); put(new Integer(id), new Double(a.trim())); } // end while ar.close(); rr.close(); }
Example #17
Source File: Play.java From restcommander with Apache License 2.0 | 6 votes |
public static void guessFrameworkPath() { // Guess the framework path try { URL versionUrl = Play.class.getResource("/play/version"); // Read the content of the file Play.version = new LineNumberReader(new InputStreamReader(versionUrl.openStream())).readLine(); // This is used only by the embedded server (Mina, Netty, Jetty etc) URI uri = new URI(versionUrl.toString().replace(" ", "%20")); if (frameworkPath == null || !frameworkPath.exists()) { if (uri.getScheme().equals("jar")) { String jarPath = uri.getSchemeSpecificPart().substring(5, uri.getSchemeSpecificPart().lastIndexOf("!")); frameworkPath = new File(jarPath).getParentFile().getParentFile().getAbsoluteFile(); } else if (uri.getScheme().equals("file")) { frameworkPath = new File(uri).getParentFile().getParentFile().getParentFile().getParentFile(); } else { throw new UnexpectedException("Cannot find the Play! framework - trying with uri: " + uri + " scheme " + uri.getScheme()); } } } catch (Exception e) { throw new UnexpectedException("Where is the framework ?", e); } }
Example #18
Source File: LanguageModelTrueCaser.java From phrasal with GNU General Public License v3.0 | 6 votes |
/** * * @param args * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length != 2) { System.err.printf("Usage: java %s lm_file uncased_input > cased_output%n", LanguageModelTrueCaser.class.getName()); System.exit(-1); } LanguageModelTrueCaser trueCaser = new LanguageModelTrueCaser(args[0]); // enter main truecasing loop LineNumberReader reader = IOTools.getReaderFromFile(args[1]); for (String line; (line = reader.readLine()) != null;) { final int inputId = reader.getLineNumber() - 1; String output = trueCaser.trueCase(line, inputId); System.out.println(output); } reader.close(); }
Example #19
Source File: ScriptUtils.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Read a script from the provided {@code LineNumberReader}, using the supplied * comment prefix and statement separator, and build a {@code String} containing * the lines. * <p>Lines <em>beginning</em> with the comment prefix are excluded from the * results; however, line comments anywhere else — for example, within * a statement — will be included in the results. * @param lineNumberReader the {@code LineNumberReader} containing the script * to be processed * @param commentPrefix the prefix that identifies comments in the SQL script — * typically "--" * @param separator the statement separator in the SQL script — typically ";" * @return a {@code String} containing the script lines * @throws IOException in case of I/O errors */ public static String readScript(LineNumberReader lineNumberReader, String commentPrefix, String separator) throws IOException { String currentStatement = lineNumberReader.readLine(); StringBuilder scriptBuilder = new StringBuilder(); while (currentStatement != null) { if (commentPrefix != null && !currentStatement.startsWith(commentPrefix)) { if (scriptBuilder.length() > 0) { scriptBuilder.append('\n'); } scriptBuilder.append(currentStatement); } currentStatement = lineNumberReader.readLine(); } appendSeparatorToScriptIfNecessary(scriptBuilder, separator); return scriptBuilder.toString(); }
Example #20
Source File: InputFormatConverter.java From bluima with Apache License 2.0 | 6 votes |
public InputFormatConverter(File in) { logger.debug("InputFormatConverter.InputFormatConverter: " + in); try { LineNumberReader lnr = new LineNumberReader(new FileReader(in)); String s; while ((s = lnr.readLine()) != null) { String[] fld = s.split("\t"); } // end while lnr.close(); } catch (IOException e) { logger.error("", e); } }
Example #21
Source File: SchemaValidator.java From vespa with Apache License 2.0 | 6 votes |
private String getErrorContext(int lineNumberWithError) { if (!(reader instanceof StringReader)) return ""; int fromLine = Math.max(0, lineNumberWithError - linesOfContextForErrors); int toLine = lineNumberWithError + linesOfContextForErrors; LineNumberReader r = new LineNumberReader(reader); StringBuilder sb = new StringBuilder(); String line; try { reader.reset(); while ((line = r.readLine()) != null) { int lineNumber = r.getLineNumber(); if (lineNumber >= fromLine && lineNumber <= toLine) sb.append(lineNumber).append(":").append(line).append("\n"); } } catch (IOException e) { e.printStackTrace(); } return sb.toString(); }
Example #22
Source File: XBootURLHandler.java From xjar with Apache License 2.0 | 6 votes |
public XBootURLHandler(XDecryptor xDecryptor, XEncryptor xEncryptor, XKey xKey, ClassLoader classLoader) throws Exception { this.xDecryptor = xDecryptor; this.xEncryptor = xEncryptor; this.xKey = xKey; this.indexes = new LinkedHashSet<>(); Enumeration<URL> resources = classLoader.getResources(XJAR_INF_DIR + XJAR_INF_IDX); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); String url = resource.toString(); String classpath = url.substring(0, url.lastIndexOf("!/") + 2); InputStream in = resource.openStream(); InputStreamReader isr = new InputStreamReader(in); LineNumberReader lnr = new LineNumberReader(isr); String name; while ((name = lnr.readLine()) != null) indexes.add(classpath + name); } }
Example #23
Source File: IrTransImporter.java From IrScrutinizer with GNU General Public License v3.0 | 6 votes |
@Override public void load(Reader reader, String origin) throws IOException, ParseException { prepareLoad(origin); LineNumberReader bufferedReader = new LineNumberReader(reader); Map<String, Remote> remotes = new HashMap<>(16); while (true) { Remote remote = parseRemote(bufferedReader); if (remote == null) break; remotes.put(remote.getName(), remote); } remoteSet = new RemoteSet(getCreatingUser(), origin, //java.lang.String source, (new Date()).toString(), //java.lang.String creationDate, Version.appName, //java.lang.String tool, Version.version, //java.lang.String toolVersion, null, //java.lang.String tool2, null, //java.lang.String tool2Version, null, //java.lang.String notes, remotes); }
Example #24
Source File: MarkSplitCRLF.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Test public static void testCRNotFollowedByLF() throws IOException { final String string = "foo\rbar"; try (Reader reader = new LineNumberReader(new StringReader(string), 5)) { reader.read(); // 'f' reader.read(); // 'o' reader.read(); // 'o' reader.read(); // '\r' reader.mark(1); // mark position of next character reader.read(); // 'b' reader.reset(); // reset to position after '\r' assertEquals(reader.read(), 'b'); assertEquals(reader.read(), 'a'); assertEquals(reader.read(), 'r'); } }
Example #25
Source File: Lines.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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"); } }
Example #26
Source File: MemoryFootprintTestCase.java From netbeans with Apache License 2.0 | 6 votes |
/** * Get PID from the {xtest.workdir}/ide.pid file. * * @return */ private String getPID() { String xtestWorkdir = System.getProperty("xtest.workdir"); if (xtestWorkdir == null) { fail("xtest.workdir property is not specified"); } File ideRunning = new File(xtestWorkdir, "ide.pid"); if (!ideRunning.exists()) { fail("Cannot find file containing PID of running IDE (" + ideRunning.getAbsolutePath()); } try { LineNumberReader reader = new LineNumberReader(new FileReader(ideRunning)); String pid = reader.readLine().trim(); log("PID = " + pid); return pid; } catch (Exception exc) { exc.printStackTrace(getLog()); fail("Exception rises when reading PID from ide.pid file"); } return ""; }
Example #27
Source File: CrashHandler.java From TestChat with Apache License 2.0 | 6 votes |
private String getStringFromFile(String error) { try { File file=new File(error); BufferedReader bufferedReader=new BufferedReader(new FileReader(file)); LineNumberReader lineNumberReader=new LineNumberReader(bufferedReader); StringBuilder stringBuilder=new StringBuilder(); String line; while ((line = lineNumberReader.readLine()) != null) { stringBuilder.append(line).append("\n"); } return stringBuilder.toString(); } catch (IOException e) { e.printStackTrace(); LogUtil.e("从文件中获取信息失败"+e.getMessage()); } return null; }
Example #28
Source File: OldLineNumberReaderTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * java.io.LineNumberReader#read(char[], int, int) */ public void test_read$CII() throws IOException { lnr = new LineNumberReader(new StringReader(text)); char[] c = new char[100]; lnr.read(c, 0, 4); assertTrue("Test 1: Read returned incorrect characters.", "0\n1\n" .equals(new String(c, 0, 4))); assertEquals("Test 2: Read failed to inc lineNumber", 2, lnr.getLineNumber()); lnr.close(); try { lnr.read(c, 0, 4); fail("Test 3: IOException expected."); } catch (IOException e) { // Expected. } }
Example #29
Source File: GPL.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
public static void main(String[] args) { LineNumberReader reader = new LineNumberReader( new InputStreamReader(System.in)); Set unknownPackageNames = unknownPackageNames(reader); if (unknownPackageNames.size() > 0) { String uniquePackageNames = uniquePackageNames(unknownPackageNames); System.out.println(uniquePackageNames); } }
Example #30
Source File: Profiler.java From fastfilter_java with Apache License 2.0 | 5 votes |
private static List<Object[]> readRunnableStackTraces(int pid) { try { String jstack = exec("jstack", "" + pid); LineNumberReader r = new LineNumberReader( new StringReader(jstack)); return readStackTrace(r); } catch (IOException e) { throw new RuntimeException(e); } }