本文整理汇总了Java中java.io.LineNumberReader.readLine方法的典型用法代码示例。如果您正苦于以下问题:Java LineNumberReader.readLine方法的具体用法?Java LineNumberReader.readLine怎么用?Java LineNumberReader.readLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.LineNumberReader
的用法示例。
在下文中一共展示了LineNumberReader.readLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDrivers
import java.io.LineNumberReader; //导入方法依赖的package包/类
private Vector<Driver> getDrivers() throws IOException {
if (mDrivers == null) {
mDrivers = new Vector<>();
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(" +");
Log.d("SerialPortFinder","drivername :"+drivername+"====="+l);
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;
}
示例2: newSingleColumnStringResult
import java.io.LineNumberReader; //导入方法依赖的package包/类
public static Result newSingleColumnStringResult(String colName,
String contents) {
Result result = Result.newSingleColumnResult(colName);
LineNumberReader lnr =
new LineNumberReader(new StringReader(contents));
while (true) {
String line = null;
try {
line = lnr.readLine();
} catch (Exception e) {}
if (line == null) {
break;
}
result.getNavigator().add(new Object[]{ line });
}
return result;
}
示例3: newSingleColumnStringResult
import java.io.LineNumberReader; //导入方法依赖的package包/类
public static Result newSingleColumnStringResult(String colName,
String contents) {
Result result = Result.newSingleColumnResult("OPERATION",
Type.SQL_VARCHAR);
LineNumberReader lnr =
new LineNumberReader(new StringReader(contents));
while (true) {
String line = null;
try {
line = lnr.readLine();
} catch (Exception e) {}
if (line == null) {
break;
}
result.getNavigator().add(new Object[]{ line });
}
return result;
}
示例4: performLoad
import java.io.LineNumberReader; //导入方法依赖的package包/类
private void performLoad ( final Reader stream )
{
final Set<ConnectionDescriptor> result = new HashSet<ConnectionDescriptor> ();
final LineNumberReader reader = new LineNumberReader ( stream );
String line;
try
{
while ( ( line = reader.readLine () ) != null )
{
final ConnectionDescriptor info = convert ( line );
if ( info != null )
{
result.add ( info );
}
}
}
catch ( final IOException e )
{
}
setConnections ( result );
}
示例5: getLineCountInLogFile
import java.io.LineNumberReader; //导入方法依赖的package包/类
private int getLineCountInLogFile() {
int linenumber = 0;
if (_logFile.exists()) {
try {
FileReader fileReader = new FileReader(_logFile);
LineNumberReader lineNumberReader = new LineNumberReader(fileReader);
while (lineNumberReader.readLine() != null) {
linenumber++;
}
lineNumberReader.close();
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
return linenumber;
}
示例6: readScript
import java.io.LineNumberReader; //导入方法依赖的package包/类
/**
* 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();
}
示例7: execLinuxCmd
import java.io.LineNumberReader; //导入方法依赖的package包/类
public static String execLinuxCmd(String cmd) {
try {
String[] cmdA = {"/bin/sh", "-c", cmd};
Process process = Runtime.getRuntime().exec(cmdA);
LineNumberReader br = new LineNumberReader(new InputStreamReader(
process.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
br.close();
process.getOutputStream().close(); // 不要忘记了一定要关
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例8: execute
import java.io.LineNumberReader; //导入方法依赖的package包/类
/**
* 执行Spark任务 TODD: Process的管理
*
* @param taskInfo
* @return
* @throws IOException
*/
public void execute(StonkTaskInfo taskInfo) throws IOException {
ProcessBuilder pb = new ProcessBuilder();
pb.directory(new File(systemConfig.getSparkK8sDir()));
pb.command(buildCommand(taskInfo));
Process p = pb.start();
LineNumberReader reader = new LineNumberReader(new InputStreamReader(p.getInputStream()));
String line = null;
if ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
示例9: copyfile
import java.io.LineNumberReader; //导入方法依赖的package包/类
private static void copyfile(File f) throws IOException {
LineNumberReader reader = new LineNumberReader(new FileReader(f));
String line = reader.readLine();
while (line != null) {
out.println(line);
line = reader.readLine();
}
reader.close();
}
示例10: compareTextFiles
import java.io.LineNumberReader; //导入方法依赖的package包/类
private void compareTextFiles(File goledFile, File outFile) throws IOException {
InputStreamReader goldenIsr = new InputStreamReader(new FileInputStream(goledFile),"UTF-8");
LineNumberReader goldenReader = new LineNumberReader(goldenIsr);
InputStreamReader isr = new InputStreamReader(new FileInputStream(outFile),"UTF-8");
LineNumberReader reader = new LineNumberReader(isr);
String goldenLine = "";
String line = "";
while(goldenLine != null && goldenLine.equals(line)) {
goldenLine = goldenReader.readLine();
line = reader.readLine();
}
assertEquals("File "+goledFile.getAbsolutePath()+" and "+outFile.getAbsolutePath()+" differs on line "+goldenReader.getLineNumber(), goldenLine, line);
}
示例11: getByCommand
import java.io.LineNumberReader; //导入方法依赖的package包/类
public static InetAddress[] getByCommand() {
try {
LineNumberReader lnr = new LineNumberReader(new InputStreamReader(Runtime.getRuntime
().exec("getprop").getInputStream()));
ArrayList<InetAddress> servers = new ArrayList(5);
while (true) {
String line = lnr.readLine();
if (line == null) {
break;
}
int split = line.indexOf("]: [");
if (split != -1) {
String property = line.substring(1, split);
String value = line.substring(split + 4, line.length() - 1);
if (property.endsWith(".dns") || property.endsWith(".dns1") || property
.endsWith(".dns2") || property.endsWith(".dns3") || property.endsWith
(".dns4")) {
InetAddress ip = InetAddress.getByName(value);
if (ip != null) {
value = ip.getHostAddress();
if (!(value == null || value.length() == 0)) {
servers.add(ip);
}
}
}
}
}
if (servers.size() > 0) {
return (InetAddress[]) servers.toArray(new InetAddress[servers.size()]);
}
} catch (IOException e) {
Logger.getLogger("AndroidDnsServer").log(Level.WARNING, "Exception in findDNSByExec",
e);
}
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: readMockParams
import java.io.LineNumberReader; //导入方法依赖的package包/类
private List<String> readMockParams() throws IOException {
LinkedList<String> ret = new LinkedList<String>();
LineNumberReader reader = new LineNumberReader(new FileReader(
mockParamFile));
String line;
while((line = reader.readLine()) != null) {
ret.add(line);
}
reader.close();
return ret;
}
示例14: unknownPackageNames
import java.io.LineNumberReader; //导入方法依赖的package包/类
/**
* Returns a set of package names from the given stack trace.
*/
private static Set unknownPackageNames(LineNumberReader reader)
{
Set packageNames = new HashSet();
try
{
while (true)
{
String line = reader.readLine();
if (line == null)
{
break;
}
line = line.trim();
if (line.startsWith("at "))
{
line = line.substring(2).trim();
line = trimSuffix(line, '(');
line = trimSuffix(line, '.');
line = trimSuffix(line, '.');
if (line.length() > 0 && !isKnown(line))
{
packageNames.add(line);
}
}
}
}
catch (IOException ex)
{
// We'll just stop looking for more names.
}
return packageNames;
}
示例15: testSeekForRwServer
import java.io.LineNumberReader; //导入方法依赖的package包/类
/**
* Ensures that client seeks for r/w servers while it's connected to r/o
* server.
*/
@SuppressWarnings("deprecation")
@Test(timeout = 90000)
public void testSeekForRwServer() throws Exception {
// setup the logger to capture all logs
Layout layout = Logger.getRootLogger().getAppender("CONSOLE")
.getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setImmediateFlush(true);
appender.setThreshold(Level.INFO);
Logger zlogger = Logger.getLogger("org.apache.zookeeper");
zlogger.addAppender(appender);
try {
qu.shutdown(2);
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zk = new ZooKeeper(qu.getConnString(),
CONNECTION_TIMEOUT, watcher, true);
watcher.waitForConnected(CONNECTION_TIMEOUT);
// if we don't suspend a peer it will rejoin a quorum
qu.getPeer(1).peer.suspend();
// start two servers to form a quorum; client should detect this and
// connect to one of them
watcher.reset();
qu.start(2);
qu.start(3);
ClientBase.waitForServerUp(qu.getConnString(), 2000);
watcher.waitForConnected(CONNECTION_TIMEOUT);
zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
// resume poor fellow
qu.getPeer(1).peer.resume();
} finally {
zlogger.removeAppender(appender);
}
os.close();
LineNumberReader r = new LineNumberReader(new StringReader(os
.toString()));
String line;
Pattern p = Pattern.compile(".*Majority server found.*");
boolean found = false;
while ((line = r.readLine()) != null) {
if (p.matcher(line).matches()) {
found = true;
break;
}
}
Assert.assertTrue(
"Majority server wasn't found while connected to r/o server",
found);
}