package com.jcomeau; import java.io.*; public class Common { public static boolean DEBUGGING = true; public static int BUFFERSIZE = 4096; public static boolean debug(String message) { if (DEBUGGING) { System.err.println(message); return true; } else return false; } public static boolean debug() {return debug("");} public static String getStreamAsString(InputStream stream) throws Exception { byte[] buffer = new byte[BUFFERSIZE]; StringBuffer bytes = new StringBuffer(); int count; while ((count = stream.read(buffer, 0, BUFFERSIZE)) > 0) { bytes.append(new String(buffer, 0, count)); } return bytes.toString(); } public static int binary(String number) { int result = 0; for (int i = 0; i < number.length(); i++) { result <<= 1; if (number.charAt(i) == '1') result |= 1; } return result; } public static void main(String[] args) throws Exception { String testString = "this is a test\n"; if (args.length > 0 && args[0].length() > 0) { testString = args[0]; } System.out.println(getStreamAsString(new DataInputStream( new ByteArrayInputStream(testString.getBytes())))); } }