List of usage examples for java.io FileNotFoundException getMessage
public String getMessage()
From source file:eu.planets_project.pp.plato.action.fte.DefineRequirementsFastTrack.java
public void useFastTrackTemplate() { if (fastTrackTemplates.getFastTrackTemplate() != null) { log.info(fastTrackTemplates.getFastTrackTemplate().getAbsolutePath()); }/* w w w. j a va2s. co m*/ File file = new File(fastTrackTemplates.getFastTrackTemplate().getAbsolutePath()); List<TemplateTree> templates = null; try { FileInputStream fis; fis = new FileInputStream(file); byte[] data = new byte[(int) file.length()]; fis.read(data); fis.close(); templates = projectImport.importTemplates(data); if (templates.size() != 1) { FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR, "Unable to load template."); return; } TreeNode newRoot = ((TreeNode) templates.get(0).getRoot()).clone(); newRoot.touchAll(user.getUsername()); //newtree.adjustScalesToMeasurements(MiniRED.getInstance().getMeasurementsDescriptor()); newRoot.initWeights(); nodesToDelete.add(selectedPlan.getTree().getRoot()); selectedPlan.getTree().setRoot(newRoot); // setWeightsInitialized must be called so that initWeights does its work selectedPlan.getTree().setWeightsInitialized(false); // initWeights *must* be called because it amongst other things // sets the weight of the root node to 1.0. if that doesn't happed // the whole evaluation doesn't work. selectedPlan.getTree().initWeights(); changed = "true"; } catch (FileNotFoundException e) { log.error(e.getMessage(), e); FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR, e.getMessage()); return; } catch (IOException e) { log.error(e.getMessage(), e); FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR, e.getMessage()); return; } catch (SAXException e) { log.error(e.getMessage(), e); } }
From source file:com.naval.gui.Gui.java
private void creerPartie() { final JFileChooser fc = new JFileChooser(Config.getRepTravail()); fc.addChoosableFileFilter(new GameFileFilter("gm", "Description de partie")); fc.setAcceptAllFileFilterUsed(false); int returnVal = fc.showOpenDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // TODO : load only if game is != try {/*from w w w. ja v a2s . co m*/ FileReader fr = new FileReader(file); partie = Partie.creer(fr); partie.save(); hintBar.setText("Partie " + partie.nom + " cre avec succes"); } catch (FileNotFoundException e) { hintBar.setText(e.getMessage()); e.printStackTrace(); } catch (IOException e) { hintBar.setText(e.getMessage()); e.printStackTrace(); } } }
From source file:meme.singularsyntax.mojo.JavaflowEnhanceMojo.java
private List<String> getClassFiles(String outputDir, File classList) throws MojoExecutionException { BufferedReader in = null;//from w ww .ja v a 2s. c om String fileName = null; List<String> classFiles = new ArrayList<String>(); try { in = new BufferedReader(new FileReader(classList)); while ((fileName = in.readLine()) != null) { // validation tests on the complete path and file File classFile = new File(outputDir, fileName); if (!classFile.exists()) throw new MojoExecutionException( String.format("Class file %s does not exist", classFile.getName())); if (!classFile.isFile()) throw new MojoExecutionException(String.format("%s is not a file", classFile.getName())); if (!classFile.getName().endsWith(".class")) throw new MojoExecutionException( String.format("%s is not a Java class file", classFile.getName())); // add the relative path only classFiles.add(fileName); } } catch (FileNotFoundException e) { throw new MojoExecutionException(e.getMessage()); } catch (IOException e) { throw new MojoExecutionException(e.getMessage()); } return (classFiles); }
From source file:gov.redhawk.efs.sca.server.internal.FileSystemImpl.java
@Override public CF.File open(final String fileName, final boolean readOnly) throws InvalidFileName, FileException { final File file = new File(this.root, fileName); if (!file.exists()) { throw new FileException(ErrorNumberType.CF_ENOENT, "No such file or directory\n"); }/* w ww. ja va2s .c o m*/ try { final FileImpl impl = new FileImpl(file, readOnly); final byte[] id = this.poa.activate_object(impl); return FileHelper.narrow(this.poa.id_to_reference(id)); } catch (final FileNotFoundException e) { throw new FileException(ErrorNumberType.CF_EIO, e.getMessage()); } catch (final ServantAlreadyActive e) { throw new FileException(ErrorNumberType.CF_EIO, e.getMessage()); } catch (final WrongPolicy e) { throw new FileException(ErrorNumberType.CF_EIO, e.getMessage()); } catch (final ObjectNotActive e) { throw new FileException(ErrorNumberType.CF_EIO, e.getMessage()); } }
From source file:gov.redhawk.efs.sca.server.internal.FileSystemImpl.java
@Override public CF.File create(final String fileName) throws InvalidFileName, FileException { final File file = new File(this.root, fileName); if (file.exists()) { throw new FileException(ErrorNumberType.CF_EEXIST, "File already exists of the name: " + fileName); }// w w w . j av a 2 s .co m try { final FileImpl impl = new FileImpl(file, false); final byte[] id = this.poa.activate_object(impl); return FileHelper.narrow(this.poa.id_to_reference(id)); } catch (final FileNotFoundException e) { throw new FileException(ErrorNumberType.CF_EIO, e.getMessage()); } catch (final ServantAlreadyActive e) { throw new FileException(ErrorNumberType.CF_EIO, e.getMessage()); } catch (final WrongPolicy e) { throw new FileException(ErrorNumberType.CF_EIO, e.getMessage()); } catch (final ObjectNotActive e) { throw new FileException(ErrorNumberType.CF_EIO, e.getMessage()); } }
From source file:com.sr.model.dao.IMahasiswaDAOImpl.java
@Override public boolean insertBiodata(Mahasiswa mhs, AkademikSR aka, FileItem foto, List<Prestasi> prestasi) { try {/*from w w w. ja va2 s . c o m*/ LobHandler lobHandler = new DefaultLobHandler(); getJdbcTemplate().update(INSERT_BIODATA, new Object[] { mhs.getNamaMhs(), mhs.getTempat_lahir(), mhs.getTanggal_lahir(), mhs.getAgama(), mhs.getKelamin(), mhs.getAlamat_asal(), mhs.getKab_kota_asal(), mhs.getProv_asal(), mhs.getNo_hp_mhs(), mhs.getNama_ayah(), mhs.getNama_ibu(), mhs.getPendidikan_ayah(), mhs.getPendidikan_ibu(), mhs.getPekerjaan_ayah(), mhs.getPekerjaan_ibu(), mhs.getPendapatan_ortu(), mhs.getNo_tel_ortu(), mhs.getNo_hp_ortu(), mhs.getAlamat_keluarga(), mhs.getNo_tel_keluarga(), mhs.getNo_hp_keluarga(), new SqlLobValue(foto.getInputStream(), (int) foto.getSize(), lobHandler), mhs.getNim() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.NUMERIC, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.VARCHAR }); getJdbcTemplate().update(INSERT_AKADEMIK, new Object[] { aka.getProdi(), aka.getIpk_masuk(), aka.getSemester(), aka.getRapor_smu(), aka.getJurusan(), aka.getFakultas(), aka.getNim() }, new int[] { Types.VARCHAR, Types.DECIMAL, Types.NUMERIC, Types.DECIMAL, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }); for (Prestasi pres : prestasi) { getJdbcTemplate().update(INSERT_PRESTASI, new Object[] { pres.getNo_sertifikat(), pres.getNim(), pres.getNama_prestasi(), pres.getJenis_prestasi() }); } return true; } catch (DataAccessException da) { System.out.println("DataAccessException" + da.getMessage()); } catch (FileNotFoundException ex) { System.out.println("FileNotFoundException " + ex.getMessage()); } catch (IOException ex) { System.out.println(ex.getMessage()); } return false; }
From source file:com.hs.mail.smtp.message.SmtpMessage.java
public MimeMessage getMimeMessage() throws MessagingException { Session session = Session.getInstance(System.getProperties(), null); InputStream is = null;//ww w. j a v a2 s . c o m try { is = new FileInputStream(getDataFile()); return new MimeMessage(session, is); } catch (FileNotFoundException e) { throw new MessagingException(e.getMessage(), e); } finally { IOUtils.closeQuietly(is); } }
From source file:de.pksoftware.springstrap.sapi.util.WebappZipper.java
/** * Zip it/*from w w w. j av a2s. c om*/ * @param zipFile output ZIP file location */ public void addResource(String resourcePath, boolean fromContext) { byte[] buffer = new byte[1024]; try { logger.info("Adding resource: {}", resourcePath); PathMatchingResourcePatternResolver resolver; if (fromContext) { resolver = new ServletContextResourcePatternResolver(servletContext); } else { resolver = new PathMatchingResourcePatternResolver(); } // Ant-style path matching Resource[] resources = resolver.getResources(resourcePath); for (Resource resource : resources) { String fileAbsolute = resource.getURL().toString(); String fileRelative = null; boolean addFile = false; if (fromContext) { //File comes from webapp folder fileRelative = "www" + servletContext.getContextPath() + ((ServletContextResource) resource).getPath(); if (!fileRelative.endsWith("/")) { addFile = true; } } else { //Files comes from webjar int jarSeparatorIndex = fileAbsolute.indexOf("!/"); if (jarSeparatorIndex != -1) { String relativeFileName = fileAbsolute.substring(jarSeparatorIndex); Pattern pathPattern = Pattern.compile("\\!\\/webjar(\\/[a-z0-9_]+)+\\/www\\/"); Matcher pathMatcher = pathPattern.matcher(relativeFileName); if (pathMatcher.find()) { fileRelative = pathMatcher.replaceFirst("www" + servletContext.getContextPath() + "/"); addFile = true; } } } if (addFile && null != fileRelative) { logger.debug("Adding File: {} => {}", fileAbsolute, fileRelative); if (null != files.get(fileRelative)) { continue; } if (fileRelative.startsWith("temp")) { logger.error(fileAbsolute); } files.put(fileRelative, resource); ZipEntry ze = new ZipEntry(fileRelative); zos.putNextEntry(ze); InputStream in = null; try { in = resource.getInputStream(); int len; while ((len = in.read(buffer)) > 0) { zos.write(buffer, 0, len); } } catch (FileNotFoundException fio) { logger.error(fio.getMessage()); } finally { if (null != in) { in.close(); } } } } zos.closeEntry(); //remember close it logger.info("Done"); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:com.carolinarollergirls.scoreboard.jetty.MediaServlet.java
protected void download(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String media = request.getParameter("media"); String type = request.getParameter("type"); try {/* ww w .j a va 2 s . co m*/ URL url = new URL(request.getParameter("url")); File typeDir = getTypeDir(media, type, true); String name = url.getPath().replaceAll("^([^/]*/)*", ""); InputStream iS = url.openStream(); OutputStream oS = new FileOutputStream(new File(typeDir, name)); IOUtils.copyLarge(iS, oS); IOUtils.closeQuietly(iS); IOUtils.closeQuietly(oS); setTextResponse(response, response.SC_OK, "Successfully downloaded 1 remote file"); } catch (MalformedURLException muE) { setTextResponse(response, response.SC_BAD_REQUEST, muE.getMessage()); } 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.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.KubernetesV2ClouddriverProfileFactory.java
private void processKubernetesAccount(KubernetesAccount account) { if (account.usesServiceAccount()) { return;/*from w w w. ja va 2 s .c om*/ } String kubeconfigFile = account.getKubeconfigFile(); String context = account.getContext(); FileInputStream is = null; try { is = new FileInputStream(kubeconfigFile); } catch (FileNotFoundException e) { throw new IllegalStateException( "No kubeconfig file '" + kubeconfigFile + "' found, but validation passed: " + e.getMessage(), e); } Object obj = yamlParser.load(is); Map<String, Object> parsedKubeconfig = objectMapper.convertValue(obj, new TypeReference<Map<String, Object>>() { }); if (StringUtils.isEmpty(context)) { context = (String) parsedKubeconfig.get("current-context"); } if (StringUtils.isEmpty(context)) { throw new HalException(Problem.Severity.FATAL, "No context specified in kubernetes account " + account.getName() + " and no 'current-context' in " + kubeconfigFile); } final String finalContext = context; String user = (String) ((List<Map<String, Object>>) parsedKubeconfig.getOrDefault("contexts", new ArrayList<>())).stream().filter(c -> c.getOrDefault("name", "").equals(finalContext)) .findFirst() .map(m -> ((Map<String, Object>) m.getOrDefault("context", new HashMap<>())).get("user")) .orElse(""); if (StringUtils.isEmpty(user)) { return; } Map<String, Object> userProperties = (Map<String, Object>) ((List<Map<String, Object>>) parsedKubeconfig .getOrDefault("users", new ArrayList<>())).stream() .filter(c -> c.getOrDefault("name", "").equals(user)).findFirst().map(u -> u.get("user")) .orElse(null); if (userProperties == null) { throw new HalException(Problem.Severity.FATAL, "No user named '" + user + "' exists in your kubeconfig file."); } Map<String, Object> authProvider = (Map<String, Object>) userProperties.get("auth-provider"); if (authProvider == null || !authProvider.getOrDefault("name", "").equals("gcp")) { return; } Map<String, String> authProviderConfig = (Map<String, String>) authProvider.get("config"); if (authProviderConfig == null) { return; } authProviderConfig.put("cmd-path", "gcloud"); try { yamlParser.dump(parsedKubeconfig, new FileWriter(kubeconfigFile)); } catch (IOException e) { throw new HalException(Problem.Severity.FATAL, "Unable to write the kubeconfig file to the staging area. This may be a user permissions issue."); } }