List of usage examples for java.io FileNotFoundException getMessage
public String getMessage()
From source file:com.blackbear.flatworm.FileCreator.java
/** * Open the newfile for writing<br> * /*w w w.j a v a 2 s .c o m*/ * @throws UnsupportedEncodingException * @throws IOException * - if there is some sort of filesystem related problem */ public void open() throws FlatwormCreatorException, UnsupportedEncodingException { // Setup buffered writer try { if (file != null) { outputStream = new FileOutputStream(file); } bufOut = new BufferedWriter(new OutputStreamWriter(outputStream, ff.getEncoding())); } catch (FileNotFoundException ex) { throw new FlatwormCreatorException(ex.getMessage()); } }
From source file:com.carolinarollergirls.scoreboard.jetty.MediaServlet.java
protected void remove(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String media = request.getParameter("media"); String type = request.getParameter("type"); String filename = request.getParameter("filename"); try {// w w w. j av a 2 s.c om File typeDir = getTypeDir(media, type, false); File f = new File(typeDir, filename); String path = f.getAbsolutePath(); if (!f.exists()) setTextResponse(response, response.SC_BAD_REQUEST, "File does not exist : " + path); else if (f.isDirectory()) setTextResponse(response, response.SC_BAD_REQUEST, "Path is a directory : " + path); else if (!f.delete()) setTextResponse(response, response.SC_BAD_REQUEST, "Could not delete file " + path); else setTextResponse(response, response.SC_OK, "Successfully removed " + path); } catch (IllegalArgumentException iaE) { setTextResponse(response, response.SC_BAD_REQUEST, iaE.getMessage()); } catch (FileNotFoundException fnfE) { setTextResponse(response, response.SC_BAD_REQUEST, fnfE.getMessage()); } }
From source file:com.intuit.tank.client.v1.script.ScriptServiceClient.java
/** * @{inheritDoc/*from www.j a v a 2 s. c om*/ */ public String updateTankScript(File f) throws RestServiceException, UniformInterfaceException { InputStream in = null; try { in = new FileInputStream(f); return updateTankScript(in); } catch (FileNotFoundException e) { throw new IllegalArgumentException(e.getMessage()); } finally { IOUtils.closeQuietly(in); } }
From source file:com.cws.esolutions.security.dao.keymgmt.impl.FileKeyManager.java
/** * @see com.cws.esolutions.security.dao.keymgmt.interfaces.KeyManager#removeKeys(java.lang.String) */// w w w . j a v a2 s . c o m public synchronized boolean removeKeys(final String guid) throws KeyManagementException { final String methodName = FileKeyManager.CNAME + "#removeKeys(final String guid) throws KeyManagementException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", guid); } boolean isComplete = false; final File keyDirectory = FileUtils.getFile(keyConfig.getKeyDirectory() + "/" + guid); try { if (!(keyDirectory.exists())) { throw new KeyManagementException("Configured key directory does not exist"); } if ((FileUtils.getFile(keyConfig.getKeyDirectory()).canWrite()) && (keyDirectory.canWrite())) { // delete the files ... for (File file : keyDirectory.listFiles()) { if (DEBUG) { DEBUGGER.debug("File: {}", file); } if (!(file.delete())) { throw new IOException("Failed to delete file: " + file); } } // ... then delete the dir if (keyDirectory.delete()) { isComplete = true; } } else { throw new IOException("Unable to remove user keys"); } } catch (FileNotFoundException fnfx) { throw new KeyManagementException(fnfx.getMessage(), fnfx); } catch (IOException iox) { throw new KeyManagementException(iox.getMessage(), iox); } return isComplete; }
From source file:io.v.android.apps.syncslides.DeckChooserFragment.java
/** * Import a slide deck from the given (local) folder. * * The folder must contain a JSON metadata file 'deck.json' with the following format: * {/*from w w w . j ava 2 s . co m*/ * "Title" : "<title>", * "Thumb" : "<filename>, * "Slides" : [ * { * "Thumb" : "<thumb_filename1>", * "Image" : "<image_filename1>", * "Note" : "<note1>" * }, * { * "Thumb" : "<thumb_filename2>", * "Image" : "<image_filename2>", * "Note" : "<note2>" * }, * * ... * ] * } * * All the filenames must be local to the given folder. */ private void importDeck(DocumentFile dir) { if (!dir.isDirectory()) { toast("Must import from a directory, got: " + dir); return; } // Read the deck metadata file. DocumentFile metadataFile = dir.findFile("deck.json"); if (metadataFile == null) { toast("Couldn't find deck metadata file 'deck.json'"); return; } JSONObject metadata = null; try { String data = new String( ByteStreams .toByteArray(getActivity().getContentResolver().openInputStream(metadataFile.getUri())), Charsets.UTF_8); metadata = new JSONObject(data); } catch (FileNotFoundException e) { toast("Couldn't open deck metadata file: " + e.getMessage()); return; } catch (IOException e) { toast("Couldn't read data from deck metadata file: " + e.getMessage()); return; } catch (JSONException e) { toast("Couldn't parse deck metadata: " + e.getMessage()); return; } try { String id = UUID.randomUUID().toString(); String title = metadata.getString("Title"); byte[] thumbData = readImage(dir, metadata.getString("Thumb")); Deck deck = DeckFactory.Singleton.get().make(title, thumbData, id); Slide[] slides = readSlides(dir, metadata); DB.Singleton.get(getActivity().getApplicationContext()).importDeck(deck, slides, null); } catch (JSONException e) { toast("Invalid format for deck metadata: " + e.getMessage()); return; } catch (IOException e) { toast("Error interpreting deck metadata: " + e.getMessage()); return; } }
From source file:com.vmware.photon.controller.common.config.ConfigBuilder.java
private void parse() throws BadConfigException { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); try {/* www . j av a 2 s . c o m*/ config = mapper.readValue(new File(configFile), configClass); } catch (FileNotFoundException e) { throw new BadConfigException("Could not find configuration file: " + configFile); } catch (JsonProcessingException e) { e.printStackTrace(); throw new BadConfigException("Could not parse configuration: " + e.getMessage(), e); } catch (IOException e) { throw new BadConfigException("Could not read configuration file" + e.getMessage(), e); } }
From source file:gov.nih.nci.cabig.caaers.web.ae.GenerateExpeditedPdfController.java
private void generateOutput(String outFile, HttpServletResponse response, Integer reportId) throws IOException { String tempDir = System.getProperty("java.io.tmpdir"); File file = new File(tempDir + File.separator + outFile); FileInputStream fileIn = null; OutputStream out = null;/*from w ww . j a v a 2s . c om*/ try { fileIn = new FileInputStream(file); response.setContentType("application/x-download"); response.setHeader("Content-Disposition", "attachment; filename=" + outFile); response.setHeader("Content-length", String.valueOf(file.length())); response.setHeader("Pragma", "private"); response.setHeader("Cache-control", "private, must-revalidate"); out = response.getOutputStream(); byte[] buffer = new byte[2048]; int bytesRead = fileIn.read(buffer); while (bytesRead >= 0) { if (bytesRead > 0) out.write(buffer, 0, bytesRead); bytesRead = fileIn.read(buffer); } } catch (FileNotFoundException e) { log.error("File not found: " + file); log.error(e.getMessage(), e); throw e; } catch (IOException e) { log.error(e.getMessage(), e); throw e; } finally { try { if (out != null) { out.flush(); out.close(); } if (fileIn != null) fileIn.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:fedora.utilities.install.Installer.java
private File buildWAR() throws InstallationFailedException { String fedoraWarName = _opts.getValue(InstallOptions.FEDORA_APP_SERVER_CONTEXT); System.out.println("Preparing " + fedoraWarName + ".war..."); // build a staging area in FEDORA_HOME try {//from w w w .j ava 2 s . c o m File warStage = new File(installDir, "fedorawar" + File.separator); warStage.mkdirs(); Zip.unzip(_dist.get(Distribution.FEDORA_WAR), warStage); // modify web.xml System.out.println("Processing web.xml"); File distWebXML = new File(warStage, "WEB-INF/web.xml"); FedoraWebXML webXML = new FedoraWebXML(distWebXML.getAbsolutePath(), _opts); Writer outputWriter = new BufferedWriter(new FileWriter(distWebXML)); webXML.write(outputWriter); outputWriter.close(); // Remove commons-collections, commons-dbcp, and commons-pool // from fedora.war if using Tomcat 5.0 String container = _opts.getValue(InstallOptions.SERVLET_ENGINE); File webinfLib = new File(warStage, "WEB-INF/lib/"); if (container.equals(InstallOptions.INCLUDED) || container.equals(InstallOptions.EXISTING_TOMCAT)) { File tomcatHome = new File(_opts.getValue(InstallOptions.TOMCAT_HOME)); File dbcp55 = new File(tomcatHome, "common/lib/naming-factory-dbcp.jar"); File dbcp6 = new File(tomcatHome, "lib/tomcat-dbcp.jar"); if (!dbcp55.exists() && !dbcp6.exists()) { new File(webinfLib, Distribution.COMMONS_COLLECTIONS).delete(); new File(webinfLib, Distribution.COMMONS_DBCP).delete(); new File(webinfLib, Distribution.COMMONS_POOL).delete(); // JDBC driver installation into common/lib for Tomcat 5.0 is // handled by ExistingTomcat50 } else { installJDBCDriver(_dist, _opts, webinfLib); } } else { installJDBCDriver(_dist, _opts, webinfLib); } // Remove log4j if using JBoss Application Server if (container.equals(InstallOptions.OTHER) && _opts.getValue(InstallOptions.USING_JBOSS).equals("true")) { new File(webinfLib, Distribution.LOG4J).delete(); } // FeSL configuration if (_opts.getBooleanValue(InstallOptions.FESL_ENABLED, false)) { File originalWsdd = new File(warStage, "WEB-INF/server-config.wsdd"); originalWsdd.renameTo(new File(warStage, "WEB-INF/server-config.wsdd.backup.original")); File feslWsdd = new File(warStage, "WEB-INF/melcoe-pep-server-config.wsdd"); feslWsdd.renameTo(new File(warStage, "WEB-INF/server-config.wsdd")); } File fedoraWar = new File(installDir, fedoraWarName + ".war"); Zip.zip(fedoraWar, warStage.listFiles()); return fedoraWar; } catch (FileNotFoundException e) { throw new InstallationFailedException(e.getMessage(), e); } catch (IOException e) { throw new InstallationFailedException(e.getMessage(), e); } }
From source file:com.michaeljones.hellohadoop.restclient.HadoopHdfsRestClient.java
public HttpMethodFuture UploadFileAsync(String redirectLocation, String localPath) { try {/* w ww . j av a2 s .c o m*/ return restImpl.PutFileAsync(redirectLocation, localPath); } catch (FileNotFoundException ex) { LOGGER.error("Hadoop async upload file not found: " + ex.getMessage()); throw new RuntimeException("Create File failed : " + ex.getMessage()); } finally { // We want to close TCP connections immediately, because garbage collection time // is non-deterministic. restImpl.Close(); } }
From source file:fi.aalto.drumbeat.drumbeatUI.DrumbeatFileHandler.java
public OutputStream receiveUpload(String filename, String mimeType) { file = null;/*from www .j a va 2 s. c o m*/ if ((filename == null) || filename.length() == 0) { Notification n = new Notification("A file has to be selected", " ", Notification.Type.ERROR_MESSAGE); n.setDelayMsec(5000); n.show(Page.getCurrent()); return null; } if (!filename.toLowerCase().endsWith(".ifc")) { Notification n = new Notification("The file extension has to be .ifc", " ", Notification.Type.ERROR_MESSAGE); n.setDelayMsec(5000); n.show(Page.getCurrent()); return null; } // Create upload stream FileOutputStream fos = null; // Stream to write to try { // Open the file for writing. file = new File(uploads + filename); fos = new FileOutputStream(file); } catch (final java.io.FileNotFoundException e) { Notification n = new Notification("Could not open file ", e.getMessage(), Notification.Type.ERROR_MESSAGE); n.setDelayMsec(5000); n.show(Page.getCurrent()); return null; } return fos; // Return the output stream to write to }