use of java.io.LineNumberReader in project robovm by robovm.
the class OldLineNumberReaderTest method test_readLine.
public void test_readLine() throws IOException {
lnr = new LineNumberReader(new StringReader(text));
assertEquals("Returned incorrect line number", 0, lnr.getLineNumber());
String line = null;
lnr.readLine();
line = lnr.readLine();
assertEquals("Test 1: Returned incorrect string;", "1", line);
assertTrue("Test 2: Returned incorrect line number:" + lnr.getLineNumber(), lnr.getLineNumber() == 2);
lnr.close();
try {
lnr.readLine();
fail("Test 3: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
use of java.io.LineNumberReader in project robovm by robovm.
the class OldLineNumberReaderTest method test_read.
/**
* java.io.LineNumberReader#read()
*/
public void test_read() throws IOException {
lnr = new LineNumberReader(new StringReader(text));
int c = lnr.read();
assertEquals("Test 1: Read returned incorrect character;", '0', c);
lnr.read();
assertEquals("Test 2: Read failed to increase the line number;", 1, lnr.getLineNumber());
lnr.close();
try {
lnr.read();
fail("Test 3: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
use of java.io.LineNumberReader in project robovm by robovm.
the class OldLineNumberReaderTest method test_markI.
public void test_markI() throws IOException {
lnr = new LineNumberReader(new StringReader(text));
String line;
lnr.skip(80);
lnr.mark(100);
line = lnr.readLine();
lnr.reset();
assertTrue("Test 1: Failed to return to marked position.", line.equals(lnr.readLine()));
lnr.close();
try {
lnr.mark(42);
fail("Test 2: IOException expected.");
} catch (IOException e) {
// Expected.
}
// The spec does not say the mark has to be invalidated
}
use of java.io.LineNumberReader in project ignite by apache.
the class JettyRestProcessorAbstractSelfTest method content.
/**
* Execute REST command and return result.
*
* @param params Command parameters.
* @return Returned content.
* @throws Exception If failed.
*/
protected String content(Map<String, String> params) throws Exception {
SB sb = new SB(restUrl());
for (Map.Entry<String, String> e : params.entrySet()) sb.a(e.getKey()).a('=').a(e.getValue()).a('&');
URL url = new URL(sb.toString());
URLConnection conn = url.openConnection();
String signature = signature();
if (signature != null)
conn.setRequestProperty("X-Signature", signature);
InputStream in = conn.getInputStream();
StringBuilder buf = new StringBuilder(256);
try (LineNumberReader rdr = new LineNumberReader(new InputStreamReader(in, "UTF-8"))) {
for (String line = rdr.readLine(); line != null; line = rdr.readLine()) buf.append(line);
}
return buf.toString();
}
use of java.io.LineNumberReader in project cuba by cuba-platform.
the class ServerRunner method stop.
protected void stop(int port, String key) {
try {
try (Socket s = new Socket(InetAddress.getByName("127.0.0.1"), port)) {
s.setSoTimeout(STOP_TIMEOUT * 1000);
try (OutputStream out = s.getOutputStream()) {
out.write((key + "\r\nstop\r\n").getBytes(StandardCharsets.UTF_8));
out.flush();
System.out.println(String.format("Waiting %,d seconds for server to stop", STOP_TIMEOUT));
LineNumberReader lin = new LineNumberReader(new InputStreamReader(s.getInputStream(), StandardCharsets.UTF_8));
String response;
while ((response = lin.readLine()) != null) {
System.out.println(String.format("Received \"%s\"", response));
if ("Stopped".equals(response)) {
System.out.println("Server reports itself as Stopped");
}
}
}
}
} catch (SocketTimeoutException e) {
System.out.println("Timed out waiting for stop confirmation");
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations