List of usage examples for java.io UnsupportedEncodingException printStackTrace
public void printStackTrace()
From source file:com.alibaba.wasp.util.ResultInHBasePrinter.java
public static void printTable(String type, String table, Configuration conf, Log LOG) throws IOException { StorageActionManager manager = new StorageActionManager(conf); try {//from w w w . j a va2s. c o m ResultScanner fmeters = manager.scan(table, new Scan()); LOG.info("rs " + type); print(fmeters, LOG); LOG.info("rs end"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } }
From source file:Main.java
private static File getRealFileName(String baseDir, String absFileName) { String[] dirs = absFileName.split("/"); File ret = new File(baseDir); String substr = null;/*w w w. j a va 2s . c o m*/ if (dirs.length > 1) { for (int i = 0; i < dirs.length - 1; i++) { substr = dirs[i]; try { substr = new String(substr.getBytes("8859_1"), "GB2312"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } ret = new File(ret, substr); if (!ret.exists()) { ret.mkdirs(); } } substr = dirs[dirs.length - 1]; try { substr = new String(substr.getBytes("8859_1"), "GB2312"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } ret = new File(ret, substr); return ret; } return ret; }
From source file:Main.java
public static File getRealFileName(String baseDir, String absFileName) { String[] dirs = absFileName.split("/"); File ret = new File(baseDir); String substr = null;//from w ww.j a va 2 s . co m if (dirs.length > 1) { for (int i = 0; i < dirs.length - 1; i++) { substr = dirs[i]; try { substr = new String(substr.getBytes("8859_1"), "GB2312"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } ret = new File(ret, substr); } Log.d(TAG, "1ret = " + ret); if (!ret.exists()) ret.mkdirs(); substr = dirs[dirs.length - 1]; try { substr = new String(substr.getBytes("8859_1"), "GB2312"); Log.d(TAG, "substr = " + substr); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } ret = new File(ret, substr); Log.d(TAG, "2ret = " + ret); return ret; } return ret; }
From source file:net.bioclipse.model.ImageWriter.java
/** * Save image to svg format//from w ww . j a va 2s . c o m * @param path the path including filename where the image is to be stored * @param chart TODO */ public static void saveImageSVG(String path, JFreeChart chart) { //First check that we have a valid chart if (chart != null) { //Create DOM objects DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); Document document = domImpl.createDocument(null, "svg", null); //Create an instance of the SVG generator SVGGraphics2D svgGenerator = new SVGGraphics2D(document); //Setting the precision apparently avoids a NullPointerException in Batik 1.5 svgGenerator.getGeneratorContext().setPrecision(6); //Render chart into SVG Graphics2D impl. chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, 400, 300), null); //Write to file boolean useCSS = true; try { Writer out = new OutputStreamWriter(new FileOutputStream(new File(path)), "UTF-8"); svgGenerator.stream(out, useCSS); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (SVGGraphics2DIOException e) { e.printStackTrace(); } } }
From source file:com.swordlord.gozer.file.GozerFileLoader.java
public static String convertInputStreamToString(InputStream is) { String strReturn = ""; if (is != null) { Writer writer = new StringWriter(); char[] buffer = new char[1024]; try {//ww w . j a va2s . co m Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } reader.close(); strReturn = writer.toString(); writer.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { } } return strReturn; }
From source file:com.connectsdk.etc.helper.HttpMessage.java
public static String encode(String str) { try {//from ww w. j av a 2 s . co m return URLEncoder.encode(str, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:com.connectsdk.etc.helper.HttpMessage.java
public static String decode(String str) { try {// ww w . j a v a 2s .c o m return URLDecoder.decode(str, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static Element appendSingleValElementEncoded(Document owner, Element appendElement, String newElemName, String newElemVal) {/* w w w . j ava 2 s . c o m*/ Element newElem; newElem = owner.createElement(newElemName); if (newElemVal != null) { String encodedVal = ""; try { encodedVal = URLEncoder.encode(newElemVal, "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } Text value = owner.createTextNode(encodedVal); newElem.appendChild(value); newElem.setAttribute("enc", "t"); newElem.setAttribute("charSet", "UTF-8"); } appendElement.appendChild(newElem); return (newElem); }
From source file:Main.java
public static String getRepsonseString(String url, Map<String, String> params) { HttpPost request = new HttpPost(url); List<NameValuePair> p = new ArrayList<NameValuePair>(); for (String key : params.keySet()) { p.add(new BasicNameValuePair(key, params.get(key))); }/* w w w. j ava2s.c o m*/ HttpClient httpClient = new DefaultHttpClient(); String result = null; try { request.setEntity(new UrlEncodedFormEntity(p, HTTP.UTF_8)); HttpResponse response = httpClient.execute(request); if (response.getStatusLine().getStatusCode() == 200) { result = new String(EntityUtils.toString(response.getEntity()).getBytes("ISO_8859_1"), "UTF-8"); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (httpClient != null) httpClient.getConnectionManager().shutdown(); } return result; }
From source file:Main.java
/** * Read text file from its InputStream./*from w w w. j a v a2 s . c om*/ * @param charset Charset of target file. * @param lines_limit The max lines to read. */ public static String readFile(InputStream inputStream, String charset, int lines_limit) { StringBuilder stringBuilder = new StringBuilder(); try { InputStreamReader inputStreamReader = new InputStreamReader(inputStream, charset); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); int i = 0; String str_buffer; while (++i <= lines_limit && (str_buffer = bufferedReader.readLine()) != null) { stringBuilder.append(str_buffer).append("\n"); } if (i >= lines_limit && lines_limit != 1) { //Indicate that the content is part of the file. stringBuilder.append(String.format("... >%d!", lines_limit)); } else if (stringBuilder.length() > 0) { //Remove the final superfluous "\n". stringBuilder.setLength(stringBuilder.length() - 1); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { } } } return stringBuilder.toString(); }