use of java.io.LineNumberReader in project cxf by apache.
the class IdlPreprocessorReaderTest method consumeReader.
private void consumeReader(final Reader includeReader) throws IOException {
LineNumberReader oReader = new LineNumberReader(includeReader);
String line = null;
do {
line = oReader.readLine();
} while (line != null);
}
use of java.io.LineNumberReader in project chipKIT32-MAX by chipKIT32.
the class StdXMLReader method startNewStream.
/**
* Starts a new stream from a Java reader. The new stream is used
* temporary to read data from. If that stream is exhausted, control
* returns to the parent stream.
*
* @param reader the non-null reader to read the new data from
* @param isInternalEntity true if the reader is produced by resolving
* an internal entity
*/
public void startNewStream(Reader reader, boolean isInternalEntity) {
StackedReader oldReader = this.currentReader;
this.readers.push(this.currentReader);
this.currentReader = new StackedReader();
if (isInternalEntity) {
this.currentReader.lineReader = null;
this.currentReader.pbReader = new PushbackReader(reader, 2);
} else {
this.currentReader.lineReader = new LineNumberReader(reader);
this.currentReader.pbReader = new PushbackReader(this.currentReader.lineReader, 2);
}
this.currentReader.systemId = oldReader.systemId;
this.currentReader.publicId = oldReader.publicId;
}
use of java.io.LineNumberReader in project jdk8u_jdk by JetBrains.
the class J2DBench method loadOptions.
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;
}
use of java.io.LineNumberReader in project sling by apache.
the class ControlListener method configure.
/**
* Read the port from the config file
* @return The port or null
*/
private boolean configure(final boolean fromConfigFile) {
boolean result = false;
if (fromConfigFile) {
final File configFile = this.getConfigFile();
if (configFile.canRead()) {
try (final LineNumberReader lnr = new LineNumberReader(new FileReader(configFile))) {
this.socketAddress = getSocketAddress(lnr.readLine());
this.secretKey = lnr.readLine();
result = true;
} catch (final IOException ignore) {
// ignore
}
}
} else {
this.socketAddress = getSocketAddress(this.listenSpec);
this.secretKey = generateKey();
result = true;
}
return result;
}
use of java.io.LineNumberReader in project sling by apache.
the class LauncherCallable method stop.
public static void stop(final Log LOG, final ProcessDescription cfg) throws Exception {
boolean isNew = false;
if (cfg.getProcess() != null || isNew) {
LOG.info("Stopping Launchpad '" + cfg.getId() + "'");
boolean destroy = true;
final int twoMinutes = 2 * 60 * 1000;
final File controlPortFile = getControlPortFile(cfg.getDirectory());
LOG.debug("Control port file " + controlPortFile + " exists: " + controlPortFile.exists());
if (controlPortFile.exists()) {
// reading control port
int controlPort = -1;
String secretKey = null;
LineNumberReader lnr = null;
String serverName = null;
try {
lnr = new LineNumberReader(new FileReader(controlPortFile));
final String portLine = lnr.readLine();
final int pos = portLine.indexOf(':');
controlPort = Integer.parseInt(portLine.substring(pos + 1));
if (pos > 0) {
serverName = portLine.substring(0, pos);
}
secretKey = lnr.readLine();
} catch (final NumberFormatException ignore) {
// we ignore this
LOG.debug("Error reading control port file " + controlPortFile, ignore);
} catch (final IOException ignore) {
// we ignore this
LOG.debug("Error reading control port file " + controlPortFile, ignore);
} finally {
IOUtils.closeQuietly(lnr);
}
if (controlPort != -1) {
final List<String> hosts = new ArrayList<String>();
if (serverName != null) {
hosts.add(serverName);
}
hosts.add("localhost");
hosts.add("127.0.0.1");
LOG.debug("Found control port " + controlPort);
int index = 0;
while (destroy && index < hosts.size()) {
final String hostName = hosts.get(index);
Socket clientSocket = null;
DataOutputStream out = null;
BufferedReader in = null;
try {
LOG.debug("Trying to connect to " + hostName + ":" + controlPort);
clientSocket = new Socket();
// set a socket timeout
clientSocket.connect(new InetSocketAddress(hostName, controlPort), twoMinutes);
// without that, read() call on the InputStream associated with this Socket is infinite
clientSocket.setSoTimeout(twoMinutes);
LOG.debug(hostName + ":" + controlPort + " connection estabilished, sending the 'stop' command...");
out = new DataOutputStream(clientSocket.getOutputStream());
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
if (secretKey != null) {
out.writeBytes(secretKey);
out.write(' ');
}
out.writeBytes("stop\n");
in.readLine();
destroy = false;
LOG.debug("'stop' command sent to " + hostName + ":" + controlPort);
} catch (final Throwable ignore) {
// catch Throwable because InetSocketAddress and Socket#connect throws unchecked exceptions
// we ignore this for now
LOG.debug("Error sending 'stop' command to " + hostName + ":" + controlPort + " due to: " + ignore.getMessage());
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
IOUtils.closeQuietly(clientSocket);
}
index++;
}
}
}
if (cfg.getProcess() != null) {
final Process process = cfg.getProcess();
if (!destroy) {
// as shutdown might block forever, we use a timeout
final long now = System.currentTimeMillis();
final long end = now + twoMinutes;
LOG.debug("Waiting for process to stop...");
while (isAlive(process) && (System.currentTimeMillis() < end)) {
try {
Thread.sleep(2500);
} catch (InterruptedException e) {
// ignore
}
}
if (isAlive(process)) {
LOG.debug("Process timeout out after 2 minutes");
destroy = true;
} else {
LOG.debug("Process stopped");
}
}
if (destroy) {
LOG.debug("Destroying process...");
process.destroy();
LOG.debug("Process destroyed");
}
cfg.setProcess(null);
}
} else {
LOG.warn("Launchpad already stopped");
}
}
Aggregations