List of usage examples for java.io FileNotFoundException toString
public String toString()
From source file:org.transdroid.daemon.Ttorrent.TtorrentAdapter.java
private String makeUploadRequest(String path, String file, Log log) throws DaemonException { try {/*www. ja v a 2s. co m*/ // Setup request using POST HttpPost httppost = new HttpPost(buildWebUIUrl(path)); File upload = new File(URI.create(file)); Part[] parts = { new FilePart("torrentfile", upload) }; httppost.setEntity(new MultipartEntity(parts, httppost.getParams())); return makeWebRequest(httppost, log); } catch (FileNotFoundException e) { throw new DaemonException(ExceptionType.FileAccessError, e.toString()); } }
From source file:gool.generator.common.CodePrinter.java
/** * Creates a new {@link CodePrinter} with a specific {@link CodeGenerator}. * //w w w.j a va 2 s .c o m * @param generator * the {@link CodeGenerator} used to produce the code. * @param outputDir * @throws Exception * @throws Exception * when the velocity engine can not be properly initialized. */ public CodePrinter(CodeGenerator generator, File outputDir, Collection<File> myFile) { this.generator = generator; this.engine = new VelocityEngine(); this.outputDir = outputDir; this.myFileToCopy = myFile; for (File fi : myFileToCopy) { File fd; String path = ""; try { int i = fi.getCanonicalPath().lastIndexOf("src") + 4; path = fi.getCanonicalPath().toString().substring(i); } catch (IOException e) { Log.e(e.toString()); } if (path.length() != fi.getName().length()) { int nbF = (path.length() - fi.getName().length() - 1); String a = path.substring(0, nbF); new File(outputDir + File.separator + a).mkdirs(); } fd = new File(outputDir + File.separator + path); try { CopierFichier(fi, fd); } catch (FileNotFoundException e1) { System.out.println(e1.toString()); } } GoolGeneratorController.setCodeGenerator(generator); try { Properties p = new Properties(); p.setProperty("resource.loader", "class"); p.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); engine.init(p); } catch (Exception e) { throw new VelocityException("The velocity engine can not be properly initialized.", e); } }
From source file:eionet.gdem.qa.XQueryService.java
/** * Request from XML/RPC client Stores the xqScript and starts a job in the workqueue. * * @param sourceURL - URL of the source XML * @param xqScript - XQueryScript to be processed * @param scriptType - xquery, xsl or xgawk */// w w w.j a v a2 s . co m public String analyze(String sourceURL, String xqScript, String scriptType) throws GDEMException { String xqFile = ""; LOGGER.info("XML/RPC call for analyze xml: " + sourceURL); // save XQScript in a text file for the WQ try { xqFile = Utils.saveStrToFile(xqScript, scriptType); } catch (FileNotFoundException fne) { throw new GDEMException("Folder does not exist: :" + fne.toString()); } catch (IOException ioe) { throw new GDEMException("Error storing XQScript into file:" + ioe.toString()); } // name for temporary output file where the esult is stored: String resultFile = Properties.tmpFolder + File.separatorChar + "gdem_" + System.currentTimeMillis() + ".html"; String newId = "-1"; // should not be returned with value -1; // start a job in the Workqueue try { // get the trusted URL from source file adapter sourceURL = SourceFileManager.getSourceFileAdapterURL(getTicket(), sourceURL, isTrustedMode()); newId = xqJobDao.startXQJob(sourceURL, xqFile, resultFile); } catch (SQLException sqe) { sqe.printStackTrace(); LOGGER.error("DB operation failed: " + sqe.toString()); throw new GDEMException("DB operation failed: " + sqe.toString()); } catch (MalformedURLException e) { e.printStackTrace(); LOGGER.error("Source file URL is wrong: " + e.toString()); throw new GDEMException("Source file URL is wrong: " + e.toString()); } catch (IOException e) { e.printStackTrace(); LOGGER.error("Error opening source file: " + e.toString()); throw new GDEMException("Error opening source file: " + e.toString()); } return newId; }
From source file:msuresh.raftdistdb.RaftClient.java
public static void GetValue(String name, String key) throws FileNotFoundException { if (key == null || key.isEmpty()) { return;/*from w ww. ja v a2 s .co m*/ } File configFile = new File(Constants.STATE_LOCATION + name + ".info"); if (!configFile.exists() || configFile.isDirectory()) { FileNotFoundException ex = new FileNotFoundException(); throw ex; } try { System.out.println("Getting key .. Hold on."); String content = new Scanner(configFile).useDelimiter("\\Z").next(); JSONObject config = (JSONObject) (new JSONParser()).parse(content); Long numPart = (Long) config.get("countPartitions"); Integer shardId = key.hashCode() % numPart.intValue(); JSONArray memberJson = (JSONArray) config.get(shardId.toString()); List<Address> members = new ArrayList<>(); for (int i = 0; i < memberJson.size(); i++) { JSONObject obj = (JSONObject) memberJson.get(i); Long port = (Long) obj.get("port"); String address = (String) obj.get("address"); members.add(new Address(address, port.intValue())); } CopycatClient client = CopycatClient.builder(members).withTransport(new NettyTransport()).build(); client.open().join(); Object str = client.submit(new GetQuery(key)).get(); System.out.println("For the key : " + key + ", the database returned the value : " + (String) str); client.close().join(); while (client.isOpen()) { Thread.sleep(1000); } } catch (Exception ex) { System.out.println(ex.toString()); } }
From source file:org.wikipedia.nirvana.nirvanabot.NewPagesWithImages.java
@Override public Data getData(NirvanaWiki wiki, String text) throws IOException, InterruptedException, ServiceError, BotFatalError { log.info("Processing data for [[" + this.pageName + "]]"); /*for (String category : categories) { log.info("Processing data of " + category); }*///from w w w .j ava 2 s. c o m PageListProcessor pageListProcessor = createPageListProcessor(); ArrayList<Revision> pageInfoListNotFiltered = pageListProcessor.getNewPages(wiki); ArrayList<Revision> pageInfoList = new ArrayList<Revision>(30); for (Revision r : pageInfoListNotFiltered) { String article = ""; long revId = r.getRevid(); long id = ((RevisionWithId) r).getId(); String title = r.getPage(); Revision page = null; try { article = wiki.getPageText(r.getPage()); } catch (java.io.FileNotFoundException e) { log.warn(e.toString() + " " + r.getPage()); // page was created and renamed or deleted after that continue; } if (NirvanaWiki.isRedirect(article)) { if (pageListProcessor.revisionAvailable()) { page = new RevisionWithImage(wiki, wiki.getRevision(revId), id, null); } else { page = new RevisionWithImage(wiki, wiki.getFirstRevision(title, true), id, null); } //log.debug("REDIRECT to: "+page.getPage()); try { article = wiki.getPageText(page.getPage()); } catch (java.io.FileNotFoundException e) { log.warn(e.toString() + " " + page.getPage()); // page was created and renamed or deleted after that continue; } //FileTools.dump(article, "dump", page.getPage()); } String image = imageFinder.findImage(wiki, commons, article); if (image != null && checkImageFree(wiki, image)) { //log.debug("found pattern"); //String image = m.group("filename").trim(); log.debug("image found = " + image); if (page == null) { page = new RevisionWithImage(wiki, revId, Calendar.getInstance(), title, "", "", false, false, true, 0, id, image); } else { ((RevisionWithImage) page).setImage(image); } pageInfoList.add(page); log.debug("adding page to list: " + title); } } sortPages(pageInfoList, pageListProcessor.revisionAvailable()); List<String> subset = new ArrayList<String>(); List<String> includedPages = new ArrayList<String>(); List<String> includedImages = new ArrayList<String>(); int count = pageInfoList.size(); count = count < maxItems ? count : maxItems; for (int i = 0; i < count; ++i) { RevisionWithImage page = (RevisionWithImage) pageInfoList.get(i); if (page.getSize() == 0) { if (pageListProcessor.revisionAvailable()) { page = new RevisionWithImage(wiki, wiki.getRevision(page.getRevid()), page.getId(), page.getImage()); } else { page = new RevisionWithImage(wiki, wiki.getFirstRevision(page.getPage()), page.getId(), page.getImage()); } } if (page != null && !usersToIgnore.contains(HTTPTools.removeEscape(page.getUser()))) { String title = HTTPTools.removeEscape(page.getPage()); String time = null; if (NirvanaBot.TIME_FORMAT.equalsIgnoreCase("long")) time = page.getTimestamp().getTime().toString(); else { time = String.format("%1$tFT%1$tTZ", page.getTimestamp()); } /* log.debug("title -> ["+title+"]"); log.debug("user -> ["+page.getUser()+"]"); log.debug("image -> ["+page.getImage()+"]"); log.debug("title2 -> "+(namespace!=0?title.substring(wiki.namespaceIdentifier(this.namespace).length()+1):title)); log.debug("user2 -> "+HTTPTools.removeEscape(page.getUser())); log.debug("time -> "+time); log.debug("format -> "+this.format);*/ String element = String.format(this.formatString, namespace != 0 ? title.substring(wiki.namespaceIdentifier(this.namespace).length() + 1) : title, HTTPTools.removeEscape(page.getUser()), time, page.getImage()); if (!subset.contains(element)) { subset.add(element); includedPages.add(title); includedImages.add(page.getImage()); log.debug("ADD new line: \t" + element); } } } ArrayList<String> archiveItems = new ArrayList<String>(); int oldCount = 0; int archiveCount = 0; // Add elements from old page if (true/*count < maxItems /*|| archive!=null*/) { String oldText = text; String[] oldItems; /*if(archive!=null)*/ /*archiveItems = new ArrayList<String>();*/ oldText = oldText.trim(); if (!header.isEmpty() && oldText.startsWith(header)) { oldText = oldText.substring(header.length()); } //FileTools.dump(footer, "dump", this.pageName +".footer.txt"); if (!footer.isEmpty() && oldText.endsWith(footer)) { oldText = oldText.substring(0, oldText.length() - footer.length()); } oldItems = oldText.split(delimeter.replace("|", "\\|")); if (delimeter.equals("\n")) log.debug("delimeter is \\n"); else if (delimeter.equals("\r")) log.debug("delimeter is \\r"); else log.debug("delimeter is " + delimeter); oldCount = oldItems.length; for (int i = 0; i < oldItems.length; ++i) { //log.debug("check old line: \t"+items[i]+""); boolean skip = false; if (oldItems[i].isEmpty()) continue; for (String image : includedImages) { if (oldItems[i].contains(image + "|")) { skip = true; log.debug("SKIP old line: \t" + oldItems[i]); break; } } if (skip) continue; if (subset.size() < maxItems) { if (!subset.contains(oldItems[i])) { subset.add(oldItems[i]); log.debug("ADD old line: \t" + oldItems[i]); } else { log.debug("SKIP old line: \t" + oldItems[i]); } } else { log.debug("ARCHIVE old line: \t" + oldItems[i]); if (archive != null) { archiveItems.add(oldItems[i]); } archiveCount++; } } } Data d = new Data(); d.newText = header + StringUtils.join(subset.toArray(), this.delimeter) + footer; if (archive != null && archiveItems != null && archiveItems.size() > 0) { d.archiveText = StringUtils.join(archiveItems.toArray(), delimeter) + "\n"; //if(archiveSettings!=null) d.archiveItems = archiveItems; } d.archiveCount = archiveCount; d.newPagesCount = subset.size() - (oldCount - archiveCount); if (d.newPagesCount < 0) d.newPagesCount = 0; log.debug("updated items count: " + subset.size()); log.debug("old items count: " + oldCount); log.debug("archive count: " + archiveCount); log.debug("new items count: " + d.newPagesCount); return d; }
From source file:eu.cloud4soa.frontend.commons.server.services.soa.ApplicationDeploymentServiceImpl.java
@Override public void migrateApplication(String applicationUriId, String paaSOfferingUriId) throws GwtSecurityException { try {//w w w. jav a2s.co m FileItem fileItem = getFileByName(artifactsHolder.getUploadedFiles(), "app-binary"); InputStream is = new FileInputStream(fileItem.getFile()); applicationMigration.migrateApplication(applicationUriId, paaSOfferingUriId, is); } catch (FileNotFoundException e) { logger.error("Error reading artifact.", e); throw new RuntimeException("Application migration failed: " + e.toString()); } catch (SOAException e) { logger.error("Error migrating the application.", e); throw new RuntimeException("Application migration failed: " + e.toString()); } }
From source file:jatoo.proxy.dialog.ProxyDialog.java
/** * Shows the dialog relative to the specified owner. *///from w w w . j a v a 2s. com public static synchronized void show(Component owner) { JDialog dialogTmp; if (owner == null) { dialogTmp = new JDialog(); } else { dialogTmp = new JDialog(SwingUtilities.getWindowAncestor(owner)); } final JDialog dialog = dialogTmp; // // the panel final ProxyDialogPanel dialogPanel = PROXY_DIALOG_PANEL_FACTORY.createDialogPanel(); try { Proxy proxy = new Proxy(); proxy.load(); dialogPanel.setProxyEnabled(proxy.isEnabled()); dialogPanel.setHost(proxy.getHost()); dialogPanel.setPort(proxy.getPort()); dialogPanel.setProxyRequiringAuthentication(proxy.isRequiringAuthentication()); dialogPanel.setUsername(proxy.getUsername()); dialogPanel.setPassword(proxy.getPassword()); } catch (FileNotFoundException e) { // do nothing, maybe is the first time and the file is missing } catch (Exception e) { logger.error("Failed to load the properties.", e); } // // buttons JButton okButton = new JButton("Ok"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { if (dialogPanel.isProxyEnabled()) { if (dialogPanel.isProxyRequiringAuthentication()) { ProxyUtils.setProxy(dialogPanel.getHost(), dialogPanel.getPort(), dialogPanel.getUsername(), dialogPanel.getPassword()); } else { ProxyUtils.setProxy(dialogPanel.getHost(), dialogPanel.getPort()); } } else { ProxyUtils.removeProxy(); } dialog.dispose(); } catch (Exception e) { JOptionPane.showMessageDialog(dialog, "Failed to set the proxy:\n" + e.toString()); return; } try { Proxy proxy = new Proxy(); proxy.setEnabled(dialogPanel.isProxyEnabled()); proxy.setUsername(dialogPanel.getUsername()); proxy.setPassword(dialogPanel.getPassword()); proxy.setRequiringAuthentication(dialogPanel.isProxyRequiringAuthentication()); proxy.setHost(dialogPanel.getHost()); proxy.setPort(dialogPanel.getPort()); proxy.store(); } catch (Exception e) { logger.error("Failed to save the properties.", e); } } }); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); // // layout dialog dialogPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JPanel buttonsGroup = new JPanel(new GridLayout(1, 2, 5, 5)); buttonsGroup.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); buttonsGroup.add(okButton); buttonsGroup.add(cancelButton); JPanel buttonsPanel = new JPanel(new BorderLayout()); buttonsPanel.add(buttonsGroup, BorderLayout.LINE_END); JPanel contentPane = new JPanel(new BorderLayout()); contentPane.add(dialogPanel, BorderLayout.CENTER); contentPane.add(buttonsPanel, BorderLayout.PAGE_END); // // setup dialog dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setTitle("Proxy Settings"); dialog.setContentPane(contentPane); dialog.pack(); dialog.setLocationRelativeTo(dialog.getOwner()); dialog.setModal(true); // // and show dialog.setVisible(true); }
From source file:org.apache.hadoop.util.TestShell.java
@Test public void testBinDirMissing() throws Throwable { FileNotFoundException ex = assertWinutilsResolveFailed(methodDir, E_DOES_NOT_EXIST); assertInString(ex.toString(), "Hadoop bin directory"); }
From source file:com.joanzapata.PDFViewActivity.java
private String readFromFile() { String ret = ""; try {/*from w w w.j av a 2 s. co m*/ InputStream inputStream = openFileInput("test.txt"); if (inputStream != null) { InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String receiveString = ""; StringBuilder stringBuilder = new StringBuilder(); while ((receiveString = bufferedReader.readLine()) != null) { stringBuilder.append(receiveString); } inputStream.close(); ret = stringBuilder.toString(); } } catch (FileNotFoundException e) { Log.e("", "File not found: " + e.toString()); } catch (IOException e) { Log.e("", "Can not read file: " + e.toString()); } return ret; }