List of usage examples for java.lang Exception toString
public String toString()
From source file:com.nubits.nubot.trading.TradeUtils.java
public static String buildQueryString(TreeMap<String, String> args, String encoding) { String result = new String(); for (String hashkey : args.keySet()) { if (result.length() > 0) { result += '&'; }/*from w ww . j av a2s . co m*/ try { result += URLEncoder.encode(hashkey, encoding) + "=" + URLEncoder.encode(args.get(hashkey), encoding); } catch (Exception ex) { LOG.severe(ex.toString()); } } return result; }
From source file:ch.descabato.browser.BackupBrowser.java
public static void main2(final String[] args) throws InterruptedException, InvocationTargetException, SecurityException, IOException { if (args.length > 1) throw new IllegalArgumentException( "SYNTAX: java... " + BackupBrowser.class.getName() + " [initialPath]"); SwingUtilities.invokeAndWait(new Runnable() { @Override//w w w.jav a 2 s .c om public void run() { tryLoadSubstanceLookAndFeel(); final JFrame f = new JFrame("OtrosVfsBrowser demo"); f.addWindowListener(finishedListener); Container contentPane = f.getContentPane(); contentPane.setLayout(new BorderLayout()); DataConfiguration dc = null; final PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); File favoritesFile = new File("favorites.properties"); propertiesConfiguration.setFile(favoritesFile); if (favoritesFile.exists()) { try { propertiesConfiguration.load(); } catch (ConfigurationException e) { e.printStackTrace(); } } dc = new DataConfiguration(propertiesConfiguration); propertiesConfiguration.setAutoSave(true); final VfsBrowser comp = new VfsBrowser(dc, (args.length > 0) ? args[0] : null); comp.setSelectionMode(SelectionMode.FILES_ONLY); comp.setMultiSelectionEnabled(true); comp.setApproveAction(new AbstractAction(Messages.getMessage("demo.showContentButton")) { @Override public void actionPerformed(ActionEvent e) { FileObject[] selectedFiles = comp.getSelectedFiles(); System.out.println("Selected files count=" + selectedFiles.length); for (FileObject selectedFile : selectedFiles) { try { FileSize fileSize = new FileSize(selectedFile.getContent().getSize()); System.out.println(selectedFile.getName().getURI() + ": " + fileSize.toString()); Desktop.getDesktop() .open(new File(new URI(selectedFile.getURL().toExternalForm()))); // byte[] bytes = readBytes(selectedFile.getContent().getInputStream(), 150 * 1024l); // JScrollPane sp = new JScrollPane(new JTextArea(new String(bytes))); // JDialog d = new JDialog(f); // d.setTitle("Content of file: " + selectedFile.getName().getFriendlyURI()); // d.getContentPane().add(sp); // d.setSize(600, 400); // d.setVisible(true); } catch (Exception e1) { LOGGER.error("Failed to read file", e1); JOptionPane.showMessageDialog(f, (e1.getMessage() == null) ? e1.toString() : e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } } }); comp.setCancelAction(new AbstractAction(Messages.getMessage("general.cancelButtonText")) { @Override public void actionPerformed(ActionEvent e) { f.dispose(); try { propertiesConfiguration.save(); } catch (ConfigurationException e1) { e1.printStackTrace(); } System.exit(0); } }); contentPane.add(comp); f.pack(); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }); while (!finished) Thread.sleep(100); }
From source file:com.keybox.manage.db.AuthDB.java
/** * auth user and return auth token if valid auth * * @param auth username and password object * @return auth token if success/*from www . j a va 2 s. co m*/ */ public static String login(Auth auth) { //check ldap first String authToken = ExternalAuthUtil.login(auth); if (StringUtils.isEmpty(authToken)) { Connection con = null; try { con = DBUtils.getConn(); //get salt for user String salt = getSaltByUsername(con, auth.getUsername()); //login PreparedStatement stmt = con .prepareStatement("select * from users where enabled=true and username=? and password=?"); stmt.setString(1, auth.getUsername()); stmt.setString(2, EncryptionUtil.hash(auth.getPassword() + salt)); ResultSet rs = stmt.executeQuery(); if (rs.next()) { auth.setId(rs.getLong("id")); authToken = UUID.randomUUID().toString(); auth.setAuthToken(authToken); auth.setAuthType(Auth.AUTH_BASIC); updateLogin(con, auth); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); } return authToken; }
From source file:com.nubits.nubot.trading.TradeUtils.java
/** * * @param args//from www .j ava 2s .c o m * @param encoding * @return */ public static String buildQueryString(HashMap<String, String> args, String encoding) { String result = new String(); for (String hashkey : args.keySet()) { if (result.length() > 0) { result += '&'; } try { result += URLEncoder.encode(hashkey, encoding) + "=" + URLEncoder.encode(args.get(hashkey), encoding); } catch (Exception ex) { LOG.severe(ex.toString()); } } return result; }
From source file:gdt.data.grain.Support.java
/** * Intersect two string arrays //ww w . j a va 2s .c om * @param list1 first array * @param list2 second array * @return the result string array. */ public static String[] intersect(String[] list1, String[] list2) { if (list2 == null || list1 == null) { return null; } Stack<String> s1 = new Stack<String>(); Stack<String> s2 = new Stack<String>(); for (String aList2 : list2) s2.push(aList2); String line$; boolean found; String member$ = null; while (!s2.isEmpty()) { try { found = false; line$ = s2.pop().toString(); if (line$ == null) continue; for (String aList1 : list1) { member$ = aList1; if (line$.equals(member$)) { found = true; break; } } if (found) Support.addItem(member$, s1); } catch (Exception e) { Logger.getLogger(Support.class.getName()).info("intersect:" + e.toString()); } } return s1.toArray(new String[0]); }
From source file:com.keybox.manage.db.UserDB.java
/** * returns users based on sort order defined * @param sortedSet object that defines sort order * @return sorted user list/*from ww w . j av a2 s . c o m*/ */ public static SortedSet getUserSet(SortedSet sortedSet) { ArrayList<User> userList = new ArrayList<>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = "order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select * from users where enabled=true " + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); ResultSet rs = stmt.executeQuery(); while (rs.next()) { User user = new User(); user.setId(rs.getLong("id")); user.setFirstNm(rs.getString(FIRST_NM)); user.setLastNm(rs.getString(LAST_NM)); user.setEmail(rs.getString(EMAIL)); user.setUsername(rs.getString(USERNAME)); user.setPassword(rs.getString(PASSWORD)); user.setAuthType(rs.getString(AUTH_TYPE)); user.setUserType(rs.getString(USER_TYPE)); userList.add(user); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); sortedSet.setItemList(userList); return sortedSet; }
From source file:com.keybox.manage.db.UserDB.java
/** * returns all admin users based on sort order defined * @param sortedSet object that defines sort order * @return sorted user list/*from w ww .j a va2 s . com*/ */ public static SortedSet getAdminUserSet(SortedSet sortedSet) { ArrayList<User> userList = new ArrayList<>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = "order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select * from users where enabled=true and user_type like '" + User.ADMINISTRATOR + "' " + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); ResultSet rs = stmt.executeQuery(); while (rs.next()) { User user = new User(); user.setId(rs.getLong("id")); user.setFirstNm(rs.getString(FIRST_NM)); user.setLastNm(rs.getString(LAST_NM)); user.setEmail(rs.getString(EMAIL)); user.setUsername(rs.getString(USERNAME)); user.setPassword(rs.getString(PASSWORD)); user.setAuthType(rs.getString(AUTH_TYPE)); user.setUserType(rs.getString(USER_TYPE)); userList.add(user); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); sortedSet.setItemList(userList); return sortedSet; }
From source file:gdt.data.grain.Support.java
/** * Get class resource as input stream. /*from ww w .jav a 2 s . c o m*/ * @param handler the class * @param resource$ the resource name. * @return input stream. */ public static InputStream getClassResource(Class<?> handler, String resource$) { try { InputStream is = handler.getResourceAsStream(resource$); if (is != null) { //System.out.println("Support:getClassResource:resource stream="+is.toString()); return is; } else { // System.out.println("Support:getClassResource:cannot get embedded resource stream for handler="+handler.getName()); ClassLoader classLoader = handler.getClassLoader(); //if(classLoader!=null) // System.out.println("Support:getClassResource:class loader="+classLoader.toString()); is = classLoader.getResourceAsStream(resource$); //if(is!=null) // System.out.println("Support:getClassResource:resourse stream="+is.toString()); //else // System.out.println("Support:getClassResource:cannot get resource stream"); String handler$ = handler.getName(); //System.out.println("Support:getClassResource:class="+handler$); String handlerName$ = handler.getSimpleName(); //System.out.println("Support:getClassResource:class name="+handlerName$); String handlerPath$ = handler$.replace(".", "/"); //System.out.println("Support:getClassResource:class path="+handlerPath$); String resourcePath$ = "src/" + handlerPath$.replace(handlerName$, resource$); //System.out.println("Support:getClassResource:resource path="+resourcePath$); ClassLoader classloader = Thread.currentThread().getContextClassLoader(); URL resourceUrl = classloader.getResource(resourcePath$); if (resourceUrl != null) { //System.out.println("Support:getClassResource:resource URL="+resourceUrl.toString()); return resourceUrl.openStream(); } else { //System.out.println("Support:getClassResource:cannot get resource URL"); } } } catch (Exception e) { Logger.getLogger(gdt.data.grain.Support.class.getName()).severe(e.toString()); } return null; }
From source file:com.streamsets.pipeline.stage.lib.hive.HiveMetastoreUtil.java
/** * Returns the hdfs paths where the avro schema is stored after serializing. * Path is appended with current time so as to have an ordering. * @param rootTableLocation Root Table Location * @return Hdfs Path String./* www . j a va2s . c om*/ */ public static String serializeSchemaToHDFS(UserGroupInformation loginUGI, final FileSystem fs, final String rootTableLocation, final String schemaJson) throws StageException { final String folderPath = rootTableLocation + HiveMetastoreUtil.SEP + HiveMetastoreUtil.HDFS_SCHEMA_FOLDER_NAME; final Path schemasFolderPath = new Path(folderPath); final String path = folderPath + SEP + HiveMetastoreUtil.AVRO_SCHEMA + DateFormatUtils.format(new Date(System.currentTimeMillis()), "yyyy-MM-dd--HH_mm_ss"); try { loginUGI.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { if (!fs.exists(schemasFolderPath)) { fs.mkdirs(schemasFolderPath); } Path schemaFilePath = new Path(path); //This will never happen unless two HMS targets are writing, we will error out for this //and let user handle this via error record handling. if (!fs.exists(schemaFilePath)) { try (FSDataOutputStream os = fs.create(schemaFilePath)) { os.writeChars(schemaJson); } } else { LOG.error(Utils.format("Already schema file {} exists in HDFS", path)); throw new IOException("Already schema file exists"); } return null; } }); } catch (Exception e) { LOG.error("Error in Writing Schema to HDFS: " + e.toString(), e); throw new StageException(Errors.HIVE_18, path, e.getMessage()); } return path; }
From source file:edu.usc.polar.CompositeNERAgreementParser.java
public static void CompositeNER(String doc, String args[]) { try {/* www . j av a 2s. c o m*/ String text; AutoDetectParser parser = new AutoDetectParser(); BodyContentHandler handler = new BodyContentHandler(); Metadata metadata = new Metadata(); InputStream stream = new FileInputStream(doc); // System.out.println(stream.toString()); parser.parse(stream, handler, metadata); // return handler.toString(); text = handler.toString(); String metaValue = metadata.toString(); System.out.println(metaValue + "Desc:: " + metadata.get("description")); String[] example = new String[1]; example[0] = text; String name = doc.replace("C:\\Users\\Snehal\\Documents\\TREC-Data\\Data", "polar.usc.edu"); name = name.replace("\\", "."); Map<String, Set<String>> list = getCoreNLP(text); Map<String, Set<String>> list1 = getOpenNLP(text); Map<String, Set<String>> list2 = getNLTKRest(text); Set<String> NLTKRestSet = combineSets(list2); Set<String> coreNLPSet = combineSets(list); Set<String> openNLPSet = combineSets(list1); /* System.out.println("list coreNLP"+JSONStringify(coreNLPSet).toJSONString()); System.out.println("list openNLPSet"+openNLPSet); System.out.println("list NLTKRestSet"+NLTKRestSet); */ JSONObject jsonObj = new JSONObject(); jsonObj.put("DOI", name); jsonObj.put("OpenNLP", JSONStringify(openNLPSet)); jsonObj.put("NLTKRest", JSONStringify(NLTKRestSet)); jsonObj.put("CoreNLP", JSONStringify(coreNLPSet)); Set<String> union = new HashSet(); union.addAll(NLTKRestSet); union.addAll(coreNLPSet); union.addAll(openNLPSet); jsonObj.put("Union", JSONStringify(union)); Set<String> intersection = new HashSet(); intersection.addAll(union); intersection.retainAll(coreNLPSet); intersection.retainAll(openNLPSet); intersection.retainAll(NLTKRestSet); jsonObj.put("Agreement", JSONStringify(intersection)); /* System.out.println(name+"\n"+openNLPSet.size()+openNLPSet.toString()+ "\n"+coreNLPSet.size()+coreNLPSet.toString()+ "\n"+NLTKRestSet.size()+NLTKRestSet.toArray()+ "\n"+intersection.size()+intersection.toArray()+ "\n"+union.size()+union.toArray()); */ //jsonObj.put("metadata",metaValue.replaceAll("\\s\\s+|\n|\t"," ")); jsonArray.add(jsonObj); if (intersection.size() > 0) { jsonAgree.add(jsonObj); JSONArray jArr = new JSONArray(); jArr.add(jsonObj); metadata.add("CompositeNER", jArr.toJSONString()); } } catch (Exception e) { System.out.println("ERROR : OpenNLP" + "|File Name" + doc.replaceAll("C:\\Users\\Snehal\\Documents\\TREC-Data", "") + " direct" + e.toString()); } }