List of usage examples for java.io UnsupportedEncodingException toString
public String toString()
From source file:com.tfm.utad.sqoopdata.SqoopVerticaDB.java
private static void sendDataToCartoDB(List<CoordinateCartoDB> result) { String url = "http://jab-utad.cartodb.com/api/v2/sql?q="; String api = "&api_key=00ffbd3278c07285554983d9713bc08c18d461b3"; HttpClient httpclient = new DefaultHttpClient(); HttpResponse response;//from w w w . j a v a 2s .co m try { StringBuilder sb = new StringBuilder(); sb.append( "INSERT INTO tfm_utad_wearables (_offset, userstr, created_date, activity, latitude, longitude, userid) VALUES "); for (int i = 0; i < result.size(); i++) { CoordinateCartoDB coordinateCartoDB = result.get(i); String date = coordinateCartoDB.getCreated_date().replace(' ', 'T'); String insert; if (i < result.size() - 1) { insert = "(" + coordinateCartoDB.getOffset() + ",'" + coordinateCartoDB.getUserstr() + "','" + date + "','" + coordinateCartoDB.getActivity() + "'," + String.valueOf(coordinateCartoDB.getLatitude()) + "," + String.valueOf(coordinateCartoDB.getLongitude()) + "," + coordinateCartoDB.getUserid() + "),"; } else { insert = "(" + coordinateCartoDB.getOffset() + ",'" + coordinateCartoDB.getUserstr() + "','" + date + "','" + coordinateCartoDB.getActivity() + "'," + String.valueOf(coordinateCartoDB.getLatitude()) + "," + String.valueOf(coordinateCartoDB.getLongitude()) + "," + coordinateCartoDB.getUserid() + ")"; } sb.append(insert); } String encode = URLEncoder.encode(sb.toString(), HTTP.UTF_8).replaceAll("\\+", "%20") .replaceAll("\\%21", "!").replaceAll("\\%27", "'").replaceAll("\\%28", "(") .replaceAll("\\%29", ")").replaceAll("\\%2C", ",").replaceAll("\\%3A", ":") .replaceAll("\\%27", "'").replaceAll("\\%7E", "~"); URI uri = new URI(url + encode + api); HttpUriRequest request = new HttpGet(uri); LOG.info("Request sending to CartoDB...:" + request.getURI().toString()); response = httpclient.execute(request); LOG.info("Response code:" + response.getStatusLine()); } catch (UnsupportedEncodingException ex) { LOG.error("UnsupportedEncodingException:" + ex.toString()); } catch (IOException ex) { LOG.error("IOException:" + ex.toString()); } catch (URISyntaxException ex) { LOG.error("URISyntaxException:" + ex.toString()); } }
From source file:gov.nih.cadsr.transform.FilesTransformation.java
public static String transformToCSV(String xmlFile, String xsltFile) { StringBuffer sb = null;//from w ww .ja v a 2 s. c o m try { String path = "/local/content/cadsrapi/transform/data/"; String ext = "txt"; File dir = new File(path); String name = String.format("%s.%s", RandomStringUtils.randomAlphanumeric(8), ext); File rf = new File(dir, name); long startTime = System.currentTimeMillis(); //Obtain a new instance of a TransformerFactory. TransformerFactory f = TransformerFactory.newInstance(); // Process the Source into a Transformer Object...Construct a StreamSource from a File. Transformer t = f.newTransformer(new StreamSource(xsltFile)); //Construct a StreamSource from input and output Source s; try { s = new StreamSource((new ByteArrayInputStream(xmlFile.getBytes("utf-8")))); Result r = new StreamResult(rf); //Transform the XML Source to a Result. t.transform(s, r); System.out.println("Tranformation completed ..."); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block System.out.println(e1.toString()); } //convert output file to string try { BufferedReader bf = new BufferedReader(new FileReader(rf)); sb = new StringBuffer(); try { while ((bf.readLine()) != null) { sb.append(bf.readLine()); System.out.println(bf.readLine()); } } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } long endTime = System.currentTimeMillis(); System.out.println("Transformation took " + (endTime - startTime) + " milliseconds"); System.out.println("Transformation took " + (endTime - startTime) / 1000 + " seconds"); } catch (TransformerConfigurationException e) { System.out.println(e.toString()); } catch (TransformerException e) { System.out.println(e.toString()); } return sb.toString(); }
From source file:com.ery.ertc.estorm.util.ToolUtil.java
public static String parseChinese(String in) { String s = null;// w w w.j av a 2s . c o m byte temp[]; if (in == null) { System.out.println("Warn:Chinese null founded!"); return new String(""); } try { temp = in.getBytes("iso-8859-1"); s = new String(temp, "GBK"); } catch (UnsupportedEncodingException e) { System.out.println("?" + e.toString()); } return s; }
From source file:com.ery.ertc.estorm.util.ToolUtil.java
public static String parseISO(String in) { String s = null;/* w ww. j av a 2 s .c om*/ byte temp[]; if (in == null) { System.out.println("Warn:Chinese null founded!"); return new String(""); } try { temp = in.getBytes("GBK"); s = new String(temp, "iso-8859-1"); } catch (UnsupportedEncodingException e) { System.out.println("?" + e.toString()); } return s; }
From source file:gov.nih.cadsr.transform.FilesTransformation.java
public static String transformFormToCSV(String xmlFile) { StringBuffer sb = null;//from ww w . ja v a 2 s . c o m try { File tf = new File("/local/content/cadsrapi/transform/xslt/", "formbuilder.xslt"); // template file String path = "/local/content/cadsrapi/transform/data/"; String ext = "txt"; File dir = new File(path); String name = String.format("%s.%s", RandomStringUtils.randomAlphanumeric(8), ext); File rf = new File(dir, name); if (tf == null || !tf.exists() || !tf.canRead()) { System.out.println("File path incorrect"); return ""; } long startTime = System.currentTimeMillis(); //Obtain a new instance of a TransformerFactory. TransformerFactory f = TransformerFactory.newInstance(); // Process the Source into a Transformer Object...Construct a StreamSource from a File. Transformer t = f.newTransformer(new StreamSource(tf)); //Construct a StreamSource from input and output Source s; try { s = new StreamSource((new ByteArrayInputStream(xmlFile.getBytes("utf-8")))); Result r = new StreamResult(rf); //Transform the XML Source to a Result. t.transform(s, r); System.out.println("Tranformation completed ..."); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block System.out.println(e1.toString()); } //convert output file to string try { BufferedReader bf = new BufferedReader(new FileReader(rf)); sb = new StringBuffer(); try { String currentLine; while ((currentLine = bf.readLine()) != null) { sb.append(currentLine).append("\n"); //System.out.println(bf.readLine()); } } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } long endTime = System.currentTimeMillis(); System.out.println("Transformation took " + (endTime - startTime) + " milliseconds"); System.out.println("Transformation took " + (endTime - startTime) / 1000 + " seconds"); } catch (TransformerConfigurationException e) { System.out.println(e.toString()); } catch (TransformerException e) { System.out.println(e.toString()); } return sb.toString(); }
From source file:URISupport.java
public static Map<String, String> parseQuery(String uri) throws URISyntaxException { try {/*w w w . j av a 2s. c o m*/ Map<String, String> rc = new HashMap<String, String>(); if (uri != null) { String[] parameters = uri.split("&"); for (int i = 0; i < parameters.length; i++) { int p = parameters[i].indexOf("="); if (p >= 0) { String name = URLDecoder.decode(parameters[i].substring(0, p), "UTF-8"); String value = URLDecoder.decode(parameters[i].substring(p + 1), "UTF-8"); rc.put(name, value); } else { rc.put(parameters[i], null); } } } return rc; } catch (UnsupportedEncodingException e) { throw (URISyntaxException) new URISyntaxException(e.toString(), "Invalid encoding").initCause(e); } }
From source file:org.apache.kylin.storage.hbase.HBaseConnection.java
private static Set<String> getFamilyNames(HTableDescriptor desc) { HashSet<String> result = Sets.newHashSet(); for (byte[] bytes : desc.getFamiliesKeys()) { try {/*from ww w.j a v a 2 s . c o m*/ result.add(new String(bytes, "UTF-8")); } catch (UnsupportedEncodingException e) { logger.error(e.toString()); } } return result; }
From source file:URISupport.java
public static String createQueryString(Map options) throws URISyntaxException { try {//from www . j a v a 2s . c om if (options.size() > 0) { StringBuffer rc = new StringBuffer(); boolean first = true; for (Iterator iter = options.keySet().iterator(); iter.hasNext();) { if (first) { first = false; } else { rc.append("&"); } String key = (String) iter.next(); String value = (String) options.get(key); rc.append(URLEncoder.encode(key, "UTF-8")); rc.append("="); rc.append(URLEncoder.encode(value, "UTF-8")); } return rc.toString(); } else { return ""; } } catch (UnsupportedEncodingException e) { throw (URISyntaxException) new URISyntaxException(e.toString(), "Invalid encoding").initCause(e); } }
From source file:gov.nih.cadsr.transform.FilesTransformation.java
public static String transformCdeToCSV(String xmlFile) { StringBuffer sb = null;/*from w w w . j av a2 s . com*/ try { File tf = new File("/local/content/cadsrapi/transform/xslt/", "cdebrowser.xslt"); // template file String path = "/local/content/cadsrapi/transform/data/"; String ext = "txt"; File dir = new File(path); String name = String.format("%s.%s", RandomStringUtils.randomAlphanumeric(8), ext); File rf = new File(dir, name); if (tf == null || !tf.exists() || !tf.canRead()) { System.out.println("File path incorrect"); return ""; } long startTime = System.currentTimeMillis(); //Obtain a new instance of a TransformerFactory. TransformerFactory f = TransformerFactory.newInstance(); // Process the Source into a Transformer Object...Construct a StreamSource from a File. Transformer t = f.newTransformer(new StreamSource(tf)); /* Source s = new StreamSource(xmlFile); Result r = new StreamResult(rf); //Transform the XML Source to a Result. t.transform(s,r); System.out.println("Tranformation completed ..."); */ //Construct a StreamSource from input and output Source s; try { s = new StreamSource((new ByteArrayInputStream(xmlFile.getBytes("utf-8")))); Result r = new StreamResult(rf); //Transform the XML Source to a Result. t.transform(s, r); System.out.println("Tranformation completed ..."); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block System.out.println(e1.toString()); } try { BufferedReader bf = new BufferedReader(new FileReader(rf)); sb = new StringBuffer(); try { String currentLine; while ((currentLine = bf.readLine()) != null) { sb.append(currentLine).append("\n"); //System.out.println(bf.readLine()); } } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } long endTime = System.currentTimeMillis(); System.out.println("Transformation took " + (endTime - startTime) + " milliseconds"); System.out.println("Transformation took " + (endTime - startTime) / 1000 + " seconds"); } catch (TransformerConfigurationException e) { System.out.println(e.toString()); e.printStackTrace(); } catch (TransformerException e) { System.out.println(e.toString()); } return sb.toString(); }
From source file:eu.crowdrec.contest.sender.RequestSenderORP.java
/** * Send a line from a logFile to an HTTP server. * /*from ww w. j ava 2s . c om*/ * @param logline the line that should by sent * * @param connection the connection to the http server, must not be null * * @return the response or null (if an error has been detected) */ static private String excutePostWithHttpClient(final String type, final String body, final String serverURL) { // define the URL parameter String urlParameters = ""; try { urlParameters = String.format("type=%s&body=%s", URLEncoder.encode(type, "UTF-8"), URLEncoder.encode(body, "UTF-8")); } catch (UnsupportedEncodingException e1) { logger.warn(e1.toString()); } PostMethod postMethod = null; try { StringRequestEntity requestEntity = new StringRequestEntity(urlParameters, "application/x-www-form-urlencoded", "UTF-8"); postMethod = new PostMethod(serverURL); postMethod.setParameter("useCache", "false"); postMethod.setRequestEntity(requestEntity); int statusCode = httpClient.executeMethod(postMethod); String response = statusCode == 200 ? postMethod.getResponseBodyAsString() : "statusCode:" + statusCode; return response.trim(); } catch (IOException e) { logger.warn("receiving response failed, ignored."); } finally { if (postMethod != null) { postMethod.releaseConnection(); } } return null; }