Created
February 23, 2016 20:47
-
-
Save AnnaBoro/17899dae369465d7879c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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