List of usage examples for java.io UnsupportedEncodingException printStackTrace
public void printStackTrace()
From source file:com.cyberway.issue.crawler.frontier.BdbMultipleWorkQueues.java
/** * Calculate the 'origin' key for a virtual queue of items * with the given classKey. This origin key will be a * prefix of the keys for all items in the queue. * // w ww. j a v a 2 s . c o m * @param classKey String key to derive origin byte key from * @return a byte array key */ static byte[] calculateOriginKey(String classKey) { byte[] classKeyBytes = null; int len = 0; try { classKeyBytes = classKey.getBytes("UTF-8"); len = classKeyBytes.length; } catch (UnsupportedEncodingException e) { // should be impossible; all JVMs must support UTF-8 e.printStackTrace(); } byte[] keyData = new byte[len + 1]; System.arraycopy(classKeyBytes, 0, keyData, 0, len); keyData[len] = 0; return keyData; }
From source file:com.cyberway.issue.crawler.frontier.BdbMultipleWorkQueues.java
/** * Calculate the insertKey that places a CrawlURI in the * desired spot. First bytes are always classKey (usu. host) * based -- ensuring grouping by host -- terminated by a zero * byte. Then 8 bytes of data ensuring desired ordering * within that 'queue' are used. The first byte of these 8 is * priority -- allowing 'immediate' and 'soon' items to * sort above regular. Next 1 byte is 'cost'. Last 6 bytes * are ordinal serial number, ensuring earlier-discovered * URIs sort before later. //from w ww .ja v a 2 s . c o m * * NOTE: Dangers here are: * (1) priorities or costs over 2^7 (signed byte comparison) * (2) ordinals over 2^48 * * Package access & static for testing purposes. * * @param curi * @return a DatabaseEntry key for the CrawlURI */ static DatabaseEntry calculateInsertKey(CrawlURI curi) { byte[] classKeyBytes = null; int len = 0; try { classKeyBytes = curi.getClassKey().getBytes("UTF-8"); len = classKeyBytes.length; } catch (UnsupportedEncodingException e) { // should be impossible; all JVMs must support UTF-8 e.printStackTrace(); } byte[] keyData = new byte[len + 9]; System.arraycopy(classKeyBytes, 0, keyData, 0, len); keyData[len] = 0; long ordinalPlus = curi.getOrdinal() & 0x0000FFFFFFFFFFFFL; ordinalPlus = ((long) curi.getSchedulingDirective() << 56) | ordinalPlus; ordinalPlus = ((((long) curi.getHolderCost()) & 0xFFL) << 48) | ordinalPlus; ArchiveUtils.longIntoByteArray(ordinalPlus, keyData, len + 1); return new DatabaseEntry(keyData); }
From source file:org.lightcouch.CouchDbClientBase.java
/** * Performs a HTTP PUT request, saves or updates a document. * @return {@link Response}//from ww w. j av a 2 s. com */ public static String modelToString(Object object) { // throw new UnsupportedOperationException(); String string = null; Map options = new HashMap<Object, Object>(); options.put(EMFJs.OPTION_INDENT_OUTPUT, false); JSONSave js = new JSONSave(options); if (object instanceof EObject) { EObject eo = (EObject) object; org.codehaus.jackson.JsonNode node = js.writeEObject(eo, eo.eResource()); string = node.toString(); } else { ByteArrayOutputStream os = new ByteArrayOutputStream(); js.writeValue(os, object); try { string = os.toString(BTSConstants.ENCODING); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return string; }
From source file:com.bytelightning.opensource.pokerface.ScriptHelperImpl.java
/** * Takes a query string, separates the constituent name-value pairs, and stores them in a SortedMap ordered by lexicographical order. * // ww w .j av a2s. co m * @return Null if there is no query string. */ private static SortedMap<String, String> CreateParameterMap(final String queryString) { if (queryString == null || queryString.isEmpty()) return null; final String[] pairs = queryString.split("&"); final Map<String, String> params = new HashMap<String, String>(pairs.length); for (final String pair : pairs) { if (pair.length() < 1) continue; String[] tokens = pair.split("=", 2); for (int j = 0; j < tokens.length; j++) { try { tokens[j] = URLDecoder.decode(tokens[j], "UTF-8"); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } } switch (tokens.length) { case 0: break; case 1: if (pair.charAt(0) == '=') params.put("", tokens[0]); else params.put(tokens[0], ""); break; case 2: default: params.put(tokens[0], tokens[1]); break; } } return new TreeMap<String, String>(params); }
From source file:org.opensourcetlapp.tl.TLLib.java
public static boolean login(String login, String pw, Handler handler, Context context) throws IOException { handler.sendEmptyMessage(TLHandler.PROGRESS_LOGIN); logout();/* w w w. j ava 2s . c o m*/ // Fetch the token HtmlCleaner cleaner = TLLib.buildDefaultHtmlCleaner(); URL url = new URL(LOGIN_URL); //TagNode node = TagNodeFromURLEx2(cleaner, url, handler, context, "<html>", false); TagNode node = TLLib.TagNodeFromURLLoginToken(cleaner, url, handler, context); String token = null; try { TagNode result = (TagNode) (node.evaluateXPath("//input")[0]); token = result.getAttributeByName("value"); } catch (XPatherException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (token == null) { return false; } // DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httpost = new HttpPost(LOGIN_URL); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair(USER_FIELD, login)); nvps.add(new BasicNameValuePair(PASS_FIELD, pw)); nvps.add(new BasicNameValuePair(REMEMBERME, "1")); nvps.add(new BasicNameValuePair("stage", "1")); nvps.add(new BasicNameValuePair("back_url", "/")); nvps.add(new BasicNameValuePair("token", token)); Log.d("token:", token); tokenField = token; if (cookieStore != null) { httpclient.setCookieStore(cookieStore); } try { httpost.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response = httpclient.execute(httpost); HttpEntity entity = response.getEntity(); Header[] headers = response.getHeaders("Set-Cookie"); if (cookieStore.getCookies().size() < 2) { loginName = null; loginStatus = false; } else { loginName = login; loginStatus = true; cookieStore = httpclient.getCookieStore(); } if (entity != null) { entity.consumeContent(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return loginStatus; }
From source file:it.isislab.dmason.util.SystemManagement.Worker.Updater.java
public static void restart(String myTopic, Address address, boolean isBatch, String topicPrefix) { logger.debug("Restart command received"); // TODO Auto-generated method stub String path;//from w ww.j av a2 s.c o m try { path = URLDecoder.decode(Updater.class.getProtectionDomain().getCodeSource().getLocation().getFile(), "UTF-8"); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); path = ""; } if (path.contains(".jar")) //from jar { File jarfile = new File(path); try { ArrayList<String> command = new ArrayList<String>(); // Luca Vicidomini command.add("java"); command.add("-cp"); command.add(jarfile.getAbsolutePath()); command.add(DMasonWorker.class.getName()); command.add(address.getIPaddress()); command.add(address.getPort()); command.add(myTopic); if (!isBatch) command.add("reset"); else command.add(topicPrefix); // As wrote by Mario // command.add("java"); // command.add("-jar"); // command.add(jarfile.getAbsolutePath()); // command.add(address.getIPaddress()); // command.add(address.getPort()); // command.add(myTopic); // if(!isBatch) // command.add("reset"); // else // command.add(topicPrefix); logger.info("Restarting with command: " + command.toString()); System.out.println("Restarting with command: " + command); ProcessBuilder builder = new ProcessBuilder(command); Process process = builder.start(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:de.geeksfactory.opacclient.apis.BaseApi.java
/** * Cleans the parameters of a URL by parsing it manually and reformatting it using {@link * URLEncodedUtils#format(java.util.List, String)} * * @param myURL the URL to clean/*from w w w.j a va 2 s .com*/ * @return cleaned URL */ public static String cleanUrl(String myURL) { String[] parts = myURL.split("\\?"); String url = parts[0]; try { if (parts.length > 1) { url += "?"; List<NameValuePair> params = new ArrayList<>(); String[] pairs = parts[1].split("&"); for (String pair : pairs) { String[] kv = pair.split("="); if (kv.length > 1) { StringBuilder join = new StringBuilder(); for (int i = 1; i < kv.length; i++) { if (i > 1) join.append("="); join.append(kv[i]); } params.add(new BasicNameValuePair(URLDecoder.decode(kv[0], "UTF-8"), URLDecoder.decode(join.toString(), "UTF-8"))); } else { params.add(new BasicNameValuePair(URLDecoder.decode(kv[0], "UTF-8"), "")); } } url += URLEncodedUtils.format(params, "UTF-8"); } return url; } catch (UnsupportedEncodingException e) { e.printStackTrace(); return myURL; } }
From source file:immf.Util.java
public static String getParameter(String header, String name) { HeaderTokenizer tokenizer = new HeaderTokenizer(header, HeaderTokenizer.MIME, true); HeaderTokenizer.Token token;/*from w ww . j a v a 2s .co m*/ StringBuffer sb = new StringBuffer(); // It is specified in first encoded-part. Encoding encoding = new Encoding(); String n; String v; try { while (true) { token = tokenizer.next(); if (token.getType() == HeaderTokenizer.Token.EOF) break; if (token.getType() != ';') continue; token = tokenizer.next(); checkType(token); n = token.getValue(); token = tokenizer.next(); if (token.getType() != '=') { throw new ParseException("Illegal token : " + token.getValue()); } token = tokenizer.next(); checkType(token); v = token.getValue(); if (n.equalsIgnoreCase(name)) { // It is not divided and is not encoded. return v; } int index = name.length(); if (!n.startsWith(name) || n.charAt(index) != '*') { // another parameter continue; } // be folded, or be encoded int lastIndex = n.length() - 1; if (n.charAt(lastIndex) == '*') { sb.append(decodeRFC2231(v, encoding)); } else { sb.append(v); } if (index == lastIndex) { // not folding break; } } return new String(sb); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } throw new InternalError(); }
From source file:CSVTools.CsvToolsApi.java
/** * Calculate a SHA1-Hash from a string//w w w . ja va 2 s. co m * @param inputString * @return * @throws NoSuchAlgorithmException */ public static String calculateSHA1HashFromString(String inputString) throws NoSuchAlgorithmException { try { crypto.update(inputString.getBytes("utf8")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } String hash = DigestUtils.sha1Hex(crypto.digest()); return hash; }
From source file:com.yyl.common.utils.excel.ExcelTools.java
public static ResponseEntity<byte[]> export(ByteArrayOutputStream bOutputStream, String fileName) { try {//from www. java 2s . c o m fileName = new String((fileName + DateUtils.formatDate(new Date(), "yyyy-MM-dd") + ".xls").getBytes(), "iso-8859-1"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } HttpHeaders headers = new HttpHeaders(); headers.setContentDispositionFormData("attachment", fileName); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); return new ResponseEntity<byte[]>(bOutputStream.toByteArray(), headers, HttpStatus.CREATED); }