import
java.io.ByteArrayInputStream;
002 | import java.io.ByteArrayOutputStream; |
003 | import java.io.IOException; |
004 | import java.io.InputStream; |
012 | public class InputStreamUtils { |
014 | final static int BUFFER_SIZE = 4096 ; |
023 | public static String InputStreamTOString(InputStream in) throws Exception{ |
025 | ByteArrayOutputStream outStream = new ByteArrayOutputStream(); |
026 | byte [] data = new byte [BUFFER_SIZE]; |
028 | while ((count = in.read(data, ,BUFFER_SIZE)) != - 1 ) |
029 | outStream.write(data, , count); |
032 | return new String(outStream.toByteArray(), "ISO-8859-1" ); |
042 | public static String InputStreamTOString(InputStream in,String encoding) throws Exception{ |
044 | ByteArrayOutputStream outStream = new ByteArrayOutputStream(); |
045 | byte [] data = new byte [BUFFER_SIZE]; |
047 | while ((count = in.read(data, ,BUFFER_SIZE)) != - 1 ) |
048 | outStream.write(data, , count); |
051 | return new String(outStream.toByteArray(), "ISO-8859-1" ); |
060 | public static InputStream StringTOInputStream(String in) throws Exception{ |
062 | ByteArrayInputStream is = new ByteArrayInputStream(in.getBytes( "ISO-8859-1" )); |
072 | public static byte [] InputStreamTOByte(InputStream in) throws IOException{ |
074 | ByteArrayOutputStream outStream = new ByteArrayOutputStream(); |
075 | byte [] data = new byte [BUFFER_SIZE]; |
077 | while ((count = in.read(data, ,BUFFER_SIZE)) != - 1 ) |
078 | outStream.write(data, , count); |
081 | return outStream.toByteArray(); |
090 | public static InputStream byteTOInputStream( byte [] in) throws Exception{ |
092 | ByteArrayInputStream is = new ByteArrayInputStream(in); |
102 | public static String byteTOString( byte [] in) throws Exception{ |
104 | InputStream is = byteTOInputStream(in); |
105 | return InputStreamTOString(is); |