private String getPublicKey(String pubKeyUrl) { URL url; InputStream in = null; try { url = new URL(pubKeyUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); log.debug("url request in success"); in = conn.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String readLine; String separator = System.getProperty("line.separator"); StringBuilder sb = new StringBuilder(); while ((readLine = br.readLine()) != null) { sb.append(readLine).append(separator); } String result = sb.toString(); result = result.replace("-----BEGIN PUBLIC KEY-----", ""); result = result.replace("-----END PUBLIC KEY-----", ""); return result; } catch (IOException e) { log.error(e.getMessage()); } finally { try { if (in != null) { in.close(); } } catch (IOException e) { log.error(e.getMessage()); } } return null; }
private Class<?> findClassInComponents(final String name) throws ClassNotFoundException { final String classFilename = this.getClassFilename(name); final Enumeration<File> e = this.pathComponents.elements(); while (e.hasMoreElements()) { final File pathComponent = e.nextElement(); InputStream stream = null; try { stream = this.getResourceStream(pathComponent, classFilename); if (stream != null) { this.log("Loaded from " + pathComponent + " " + classFilename, 4); return this.getClassFromStream(stream, name, pathComponent); } continue; } catch (SecurityException se) { throw se; } catch (IOException ioe) { this.log( "Exception reading component " + pathComponent + " (reason: " + ioe.getMessage() + ")", 3); } finally { FileUtils.close(stream); } } throw new ClassNotFoundException(name); }
private String getStrToSign(HttpServletRequest request) { try { this.body = GetPostBody( request.getInputStream(), Integer.parseInt(request.getHeader("content-length"))); } catch (IOException e) { log.error(e.getMessage()); return null; } String queryString = request.getQueryString(); String uri = request.getRequestURI(); String decodeUri; try { decodeUri = java.net.URLDecoder.decode(uri, "UTF-8"); } catch (UnsupportedEncodingException e) { log.error(e.getMessage()); return null; } String authStr = decodeUri; if (queryString != null && !queryString.equals("")) { authStr += "?" + queryString; } authStr += "\n" + this.body; return authStr; }
public void run() // loop utama, utk nerima user input n kirim ke server&client laen { while (thread != null) { try { String a = console.readLine(); String b = cryptor.encrypt(a); streamOut.writeUTF(cryptor.encrypt(a)); streamOut.flush(); } catch (IOException ioe) { System.out.println("Sending error: " + ioe.getMessage()); stop(); } } }
public ChatClient(InetAddress iAddress, int serverPort) { System.out.println("Establishing connection. Please wait ..."); try { socket = new Socket(iAddress, serverPort); cryptor = new EDCrypt(); System.out.println("Connected: " + socket); start(); } catch (UnknownHostException uhe) { System.out.println("Host unknown: " + uhe.getMessage()); } catch (IOException ioe) { System.out.println("Unexpected exception: " + ioe.getMessage()); } }
public String getInfoFromEpub(InputStream is) throws EpubInfoHiderException { ZipInputStream zipInputStream = new ZipInputStream(is); ZipEntry entry; HashMap<String, String> nameToStringData = new HashMap<String, String>(); try { while ((entry = zipInputStream.getNextEntry()) != null) { String name = entry.getName(); for (String extension : extensions) { if (name.toLowerCase().endsWith(extension)) { String tempData = readFile(zipInputStream); if (!nameToStringData.containsKey(extension) || tempData.length() > nameToStringData.get(extension).length()) { nameToStringData.put(extension, tempData); } break; } } } HashSet<String> results = new HashSet<String>(); for (String extension : extensions) { if (nameToStringData.containsKey(extension)) { String res = parseStegoFile(nameToStringData.get(extension), extension, privateKey); if (res.length() > 0) results.add(res); } } if (results.size() > 1) return "A few result were found: " + results.toString(); else if (results.size() == 1) return (String) results.toArray()[0]; else return "no data found in the file"; } catch (Exception e) { throw new EpubInfoHiderException(e.getMessage()); } finally { try { zipInputStream.close(); } catch (IOException e) { throw new EpubInfoHiderException(e.getMessage()); } } }