public static String streamToString(InputStream instream, String charset) {
		StringWriter writer = new StringWriter();
		BufferedReader br = null;
		
		try {
			if (charset != null) {			
				br = new BufferedReader(new InputStreamReader(instream,charset));
			} else {
				br = new BufferedReader(new InputStreamReader(instream));
			}
			
			char[] buffer = new char[1024];
			int n;
			while ((n = br.read(buffer)) != -1) {
				writer.write(buffer,0,n);
			}
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				instream.close();
				if (br != null) br.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return writer.toString();
	}