@Test public void testRead() throws IOException { testConvertBoth("Line 1\r\nLine 2\r\n", "Line 1\r\nLine 2\r\n"); testConvertCR("Line 1\r\nLine 2\r\n", "Line 1\r\nLine 2\r\n"); testConvertLF("Line 1\r\nLine 2\r\n", "Line 1\r\nLine 2\r\n"); testConvertBoth("Line 1\n\rLine 2\n\r", "Line 1\r\n\r\nLine 2\r\n\r\n"); testConvertCR("Line 1\n\rLine 2\n\r", "Line 1\n\r\nLine 2\n\r\n"); testConvertLF("Line 1\n\rLine 2\n\r", "Line 1\r\n\rLine 2\r\n\r"); testConvertBoth("Line 1\nLine 2\n", "Line 1\r\nLine 2\r\n"); testConvertCR("Line 1\nLine 2\n", "Line 1\nLine 2\n"); testConvertLF("Line 1\nLine 2\n", "Line 1\r\nLine 2\r\n"); testConvertBoth("Line 1\rLine 2\r", "Line 1\r\nLine 2\r\n"); testConvertCR("Line 1\rLine 2\r", "Line 1\r\nLine 2\r\n"); testConvertLF("Line 1\rLine 2\r", "Line 1\rLine 2\r"); testConvertBoth("\r\n", "\r\n"); testConvertCR("\r\n", "\r\n"); testConvertLF("\r\n", "\r\n"); testConvertBoth("\n", "\r\n"); testConvertCR("\n", "\n"); testConvertLF("\n", "\r\n"); testConvertBoth("\r", "\r\n"); testConvertCR("\r", "\r\n"); testConvertLF("\r", "\r"); testConvertBoth("", ""); testConvertCR("", ""); testConvertLF("", ""); }
@Override public int read() throws IOException { int b = in.read(); if (b == -1) { return -1; } if ((flags & CONVERT_CR) != 0 && b == '\r') { int c = in.read(); if (c != -1) { in.unread(c); } if (c != '\n') { in.unread('\n'); } } else if ((flags & CONVERT_LF) != 0 && b == '\n' && previous != '\r') { b = '\r'; in.unread('\n'); } previous = b; return b; }
EOLConvertingInputStream extends InputStream { @Override public int read() throws IOException { int b = in.read(); if (b == -1) { return -1; } if ((flags & CONVERT_CR) != 0 && b == '\r') { int c = in.read(); if (c != -1) { in.unread(c); } if (c != '\n') { in.unread('\n'); } } else if ((flags & CONVERT_LF) != 0 && b == '\n' && previous != '\r') { b = '\r'; in.unread('\n'); } previous = b; return b; } }
EOLConvertingInputStream extends InputStream { @Override public int read() throws IOException { int b = in.read(); if (b == -1) { return -1; } if ((flags & CONVERT_CR) != 0 && b == '\r') { int c = in.read(); if (c != -1) { in.unread(c); } if (c != '\n') { in.unread('\n'); } } else if ((flags & CONVERT_LF) != 0 && b == '\n' && previous != '\r') { b = '\r'; in.unread('\n'); } previous = b; return b; } EOLConvertingInputStream(InputStream in);  EOLConvertingInputStream(InputStream in, int flags); }
EOLConvertingInputStream extends InputStream { @Override public int read() throws IOException { int b = in.read(); if (b == -1) { return -1; } if ((flags & CONVERT_CR) != 0 && b == '\r') { int c = in.read(); if (c != -1) { in.unread(c); } if (c != '\n') { in.unread('\n'); } } else if ((flags & CONVERT_LF) != 0 && b == '\n' && previous != '\r') { b = '\r'; in.unread('\n'); } previous = b; return b; } EOLConvertingInputStream(InputStream in);  EOLConvertingInputStream(InputStream in, int flags); @Override void close(); @Override int read(); }
EOLConvertingInputStream extends InputStream { @Override public int read() throws IOException { int b = in.read(); if (b == -1) { return -1; } if ((flags & CONVERT_CR) != 0 && b == '\r') { int c = in.read(); if (c != -1) { in.unread(c); } if (c != '\n') { in.unread('\n'); } } else if ((flags & CONVERT_LF) != 0 && b == '\n' && previous != '\r') { b = '\r'; in.unread('\n'); } previous = b; return b; } EOLConvertingInputStream(InputStream in);  EOLConvertingInputStream(InputStream in, int flags); @Override void close(); @Override int read(); static final int CONVERT_CR; static final int CONVERT_LF; static final int CONVERT_BOTH; }