Search in sources :

Example 51 with LineNumberReader

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.
    }
}
Also used : StringReader(java.io.StringReader) IOException(java.io.IOException) LineNumberReader(java.io.LineNumberReader)

Example 52 with LineNumberReader

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.
    }
}
Also used : StringReader(java.io.StringReader) IOException(java.io.IOException) LineNumberReader(java.io.LineNumberReader)

Example 53 with LineNumberReader

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
}
Also used : StringReader(java.io.StringReader) IOException(java.io.IOException) LineNumberReader(java.io.LineNumberReader)

Example 54 with LineNumberReader

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();
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) URL(java.net.URL) URLConnection(java.net.URLConnection) SB(org.apache.ignite.internal.util.typedef.internal.SB) LineNumberReader(java.io.LineNumberReader)

Example 55 with LineNumberReader

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();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) OutputStream(java.io.OutputStream) LineNumberReader(java.io.LineNumberReader)

Aggregations

LineNumberReader (java.io.LineNumberReader)401 IOException (java.io.IOException)203 InputStreamReader (java.io.InputStreamReader)167 FileReader (java.io.FileReader)102 File (java.io.File)79 InputStream (java.io.InputStream)64 StringReader (java.io.StringReader)64 ArrayList (java.util.ArrayList)54 FileInputStream (java.io.FileInputStream)33 BufferedReader (java.io.BufferedReader)27 PrintWriter (java.io.PrintWriter)25 HashMap (java.util.HashMap)22 FileNotFoundException (java.io.FileNotFoundException)20 BufferedWriter (java.io.BufferedWriter)16 FileWriter (java.io.FileWriter)16 Pattern (java.util.regex.Pattern)16 Test (org.junit.jupiter.api.Test)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 Reader (java.io.Reader)14