Skip to content

Instantly share code, notes, and snippets.

@AnnaBoro
Created February 23, 2016 20:47
Show Gist options
  • Save AnnaBoro/17899dae369465d7879c to your computer and use it in GitHub Desktop.
Save AnnaBoro/17899dae369465d7879c to your computer and use it in GitHub Desktop.
package lesson8.stream;
import java.io.ByteArrayInputStream;
public class DemoStream {
public static void main (String[] args) {
DemoStream demoStream = new DemoStream();
String str = "Demo demo";
byte[] bytes = {1, 2, -2, -126, 0};
ByteArrayInputStream b = new ByteArrayInputStream(str.getBytes());
ByteArrayInputStream b2 = new ByteArrayInputStream(bytes);
demoStream.printStreamData(b);
demoStream.printStreamData(b2);
// demoStream.intToByte();
}
public void intToByte() {
for (int i = 0; i <= 300; i++) {
System.out.print(((byte) i) + " ");
}
}
public void printStreamData(ByteArrayInputStream b) {
int i;
while ((i = b.read()) != -1) {
System.out.print((byte)i + " ");
}
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment