package study.hard.javalib.encodingstring;

import static org.junit.Assert.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;

import org.apache.commons.lang.StringUtils;
import org.junit.Test;

public class InputStreamTest {

	@Test
	public void testBytesRead() throws IOException {
		URL url = new URL("http://www.google.com");
		StringBuilder stringBuilder = new StringBuilder();
		BufferedReader bufferedReader = null;

		try {
			InputStream inputStream = url.openStream();
			if (inputStream != null) {
				bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
				char[] charBuffer = new char[1024];
				int bytesRead = -1;
				while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
					stringBuilder.append(charBuffer, 0, bytesRead);
				}
			} else {
				stringBuilder.append("");
			}
		} catch (IOException ex) {
			throw ex;
		} finally {
			if (bufferedReader != null) {
				try {
					bufferedReader.close();
				} catch (IOException ex) {
					throw ex;
				}
			}
		}

		assertTrue(StringUtils.isNotBlank(stringBuilder.toString()));
		System.out.println("> " + stringBuilder);
		System.out.println("length: " + stringBuilder.length());
	}

}

@@ -185,32 +185,71 @@
 utStreamReader;%0A
+import java.net.MalformedURLException;%0A
 import java.net.
@@ -253,16 +253,16 @@
 et.URL;%0A
-
 import j
@@ -294,16 +294,45 @@
 harsets;
+%0Aimport java.util.LinkedList;
 %0A%0Aimport
@@ -369,16 +369,41 @@
 gUtils;%0A
+import org.junit.Before;%0A
 import o
@@ -450,16 +450,142 @@
 Test %7B%0A%0A
+%09private URL url;%0A%0A%09@Before%0A%09public void setUp() throws MalformedURLException %7B%0A%09%09url = new URL(%22http://www.google.com%22);%0A%09%7D%0A%0A
 %09@Test%0A%09
@@ -637,54 +637,8 @@
 n %7B%0A
-%09%09URL url = new URL(%22http://www.google.com%22);%0A
 %09%09St
@@ -1508,10 +1508,762 @@
 ));%0A%09%7D%0A%0A
+%09@Test%0A%09public void testReadLine() throws IOException %7B%0A%09%09LinkedList%3CString%3E lines = new LinkedList%3CString%3E();%0A%09%09BufferedReader bufferedReader = null;%0A%0A%09%09try %7B%0A%09%09%09InputStream inputStream = url.openStream();%0A%09%09%09if (inputStream != null) %7B%0A%09%09%09%09bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));%0A%09%09%09%09String readLine;%0A%09%09%09%09while ((readLine = bufferedReader.readLine()) != null) %7B%0A%09%09%09%09%09lines.add(readLine);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D catch (IOException ex) %7B%0A%09%09%09throw ex;%0A%09%09%7D finally %7B%0A%09%09%09if (bufferedReader != null) %7B%0A%09%09%09%09try %7B%0A%09%09%09%09%09bufferedReader.close();%0A%09%09%09%09%7D catch (IOException ex) %7B%0A%09%09%09%09%09throw ex;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09assertTrue(0 %3C lines.size());%0A%09%09for (String line : lines) %7B%0A%09%09%09System.out.println(%22%3E %22 + line);%0A%09%09%7D%0A%09%7D%0A
 %7D%0A

Add some code to test ReadLine.