List of usage examples for java.io FileNotFoundException getMessage
public String getMessage()
From source file:com.l2jfree.gameserver.util.DynamicExtension.java
/** * initialize all configured extensions/*from www.j av a 2 s . co m*/ * */ public void initExtensions() { _prop = new L2Properties(); _loadedExtensions = new ConcurrentHashMap<String, Object>(); try { _prop.load(new FileInputStream(CONFIG)); } catch (FileNotFoundException ex) { _log.info(ex.getMessage() + ": no extensions to load", ex); } catch (Exception ex) { _log.warn("could not load properties", ex); } classLoader = new JarClassLoader(); for (Object o : _prop.keySet()) { String k = (String) o; if (k.endsWith("Class")) { initExtension(_prop.getProperty(k)); } } }
From source file:com.justcloud.osgifier.service.impl.SpringServiceImpl.java
private SpringContext readFile(File f) { BufferedReader reader = null; SpringContext result = null;/* w w w . ja v a 2 s . c om*/ try { reader = new BufferedReader(new FileReader(f)); result = deserializer.deserialize(reader); } catch (FileNotFoundException e) { Logger.getLogger(UserServiceImpl.class.getName()).severe(e.getMessage()); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { Logger.getLogger(UserServiceImpl.class.getName()).severe(e.getMessage()); } } } return result; }
From source file:org.yamj.filescanner.tools.XmlTools.java
/** * Save a file to disk/*from w ww . ja v a 2 s . c om*/ * * @param <T> * @param filename * @param objectToSave */ public <T> void save(String filename, T objectToSave) { LOG.info("Attempting to save {} to {}", objectToSave.getClass().getSimpleName(), filename); FileOutputStream os = null; try { os = new FileOutputStream(filename); marshaller.marshal(objectToSave, new StreamResult(os)); LOG.info("Saving completed"); } catch (FileNotFoundException ex) { LOG.warn("File not found: {}", filename); } catch (IOException ex) { LOG.warn("IO exception for: {}, Error: {}", filename, ex.getMessage()); } catch (XmlMappingException ex) { LOG.warn("XML Mapping error for: {}, Error: {}", filename, ex.getMessage()); } finally { if (os != null) { try { os.close(); } catch (IOException ex) { LOG.warn("Failed to close library file: {}, Error: {}", filename, ex.getMessage()); } } } LOG.info("Failed to save '{}'. Please check it for errors", filename); }
From source file:org.yamj.filescanner.tools.XmlTools.java
/** * Read a file from disk//from w w w . j a va2 s. c om * * @param <T> * @param filename * @param clazz * @return */ public <T> T read(String filename, Class<T> clazz) { LOG.debug("Reading filename '{}' of type {}", filename, clazz.getSimpleName()); // http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/oxm.html FileInputStream is = null; try { is = new FileInputStream(filename); return (T) unmarshaller.unmarshal(new StreamSource(is)); } catch (FileNotFoundException ex) { LOG.warn("File not found '{}'", filename); } catch (IOException ex) { LOG.warn("IO exception for '{}', Error: {}", filename, ex.getMessage()); } catch (XmlMappingException ex) { LOG.warn("XML Mapping error for '{}', Error: {}", filename, ex.getMessage()); } catch (StreamException ex) { LOG.warn("Stream exception for '{}', Error {}", filename, ex.getMessage()); } finally { if (is != null) { try { is.close(); } catch (IOException ex) { LOG.warn("Failed to close library file '{}', Error: {}", filename, ex.getMessage()); } } } return null; }
From source file:com.alibaba.otter.shared.common.utils.NioUtils.java
/** * ??jvm/*from www . jav a2s . c o m*/ * * @param dest * @param retryTimes */ public static boolean delete(File dest, final int retryTimes) { if (dest == null) { return false; } if (false == dest.exists()) { return true; } int totalRetry = retryTimes; if (retryTimes < 1) { totalRetry = 1; } int retry = 0; while (retry++ < totalRetry) { try { FileUtils.forceDelete(dest); return true; } catch (FileNotFoundException ex) { return true; } catch (Exception ex) { // int wait = (int) Math.pow(retry, retry) * timeWait; wait = (wait < timeWait) ? timeWait : wait; if (retry == totalRetry) { try { FileUtils.forceDeleteOnExit(dest); return false; } catch (Exception e) { // ignore } } else { // logger.warn(String.format("[%s] delete() - retry %s failed : wait [%s] ms , caused by %s", dest.getAbsolutePath(), retry, wait, ex.getMessage())); try { Thread.sleep(wait); } catch (InterruptedException e) { // ignore } } } } return false; }
From source file:edu.lternet.pasta.datapackagemanager.dataserver.DataServerServlet.java
/** * Process a data download HEAD request using information that was generated * by the Data Package Manager service./*from ww w.ja va2 s . co m*/ */ protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException { String dataToken = request.getParameter("dataToken"); String size = request.getParameter("size"); String objectName = request.getParameter("objectName"); if (dataToken == null || dataToken.isEmpty() || size == null || size.isEmpty() || objectName == null || objectName.isEmpty()) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } else { /* * Find out which directory the temporary data files are being * placed in by the Data Package Manager */ PropertiesConfiguration options = ConfigurationListener.getOptions(); String tmpDir = options.getString("datapackagemanager.tmpDir"); if (tmpDir == null || tmpDir.equals("")) { throw new ServletException("datapackagemanager.tmpDir property value was not specified."); } try { // reads input file from an absolute path String filePath = String.format("%s/%s", tmpDir, dataToken); File downloadFile = new File(filePath); if (!downloadFile.exists()) { String message = String.format("File not found: %s", filePath); throw new FileNotFoundException(message); } ServletContext context = getServletContext(); // gets MIME type of the file String mimeType = context.getMimeType(filePath); if (mimeType == null) { // set to binary type if MIME mapping not found mimeType = "application/octet-stream"; } // modifies response response.setContentType(mimeType); long length = Long.parseLong(size); if (length <= Integer.MAX_VALUE) { response.setContentLength((int) length); } else { response.addHeader("Content-Length", Long.toString(length)); } // forces download String headerKey = "Content-Disposition"; String headerValue = String.format("attachment; filename=\"%s\"", objectName); response.setHeader(headerKey, headerValue); } catch (FileNotFoundException e) { logger.error(e.getMessage()); e.printStackTrace(); response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } }
From source file:io.fabric8.tooling.archetype.ArchetypeUtils.java
/** * Checks if the passed POM file describes project with packaging other than <code>pom</code>. * * @param pom/*from w w w . java 2 s .co m*/ * @return */ public boolean isValidProjectPom(File pom) { Document doc = null; try { doc = parseXml(new InputSource(new FileReader(pom))); } catch (FileNotFoundException e) { throw new RuntimeException(e.getMessage(), e); } Element root = doc.getDocumentElement(); String packaging = firstElementText(root, "packaging", ""); return packaging == null || !packaging.equals("pom"); }
From source file:com.tcloud.bee.key.server.service.impl.SaslServiceImpl.java
private SaslParam sendData(SaslParam saslParam) throws IOException { SaslParam param = new SaslParam(saslParam.getCommand()); KeySaslServer saslServer = this.getServer(saslParam.getSaslId()); if (saslServer == null) { param.setData("".getBytes()); logger.warn("Abnormal behavior! saslServer is null."); } else if (saslServer.getSaslAuthStatus().equals(SaslUtil.SaslAuthStatus.AUTH_SUCCESS)) { //byte[] encrypted = saslServer.dataProcess(saslParam.getdata()); byte[] dataBytes = saslServer.dataProcess(saslParam.getdata(), false); //use username & keyName to get real key hex string String keyName = new String(dataBytes); String tokenUser = saslServer.getTokenUser(); String keyHexString = ""; try {/*from w w w. ja v a 2 s . c o m*/ KeyManageService.QueryResult queryResult = keyManageService.getHexkey(keyName, tokenUser); if (queryResult.status == BeeConstants.ResponseStatus.SUCCESS) { keyHexString = queryResult.msg; } else { logger.warn("Get key Fail: keyName: " + keyName + ",msg: " + queryResult.msg); } } catch (FileNotFoundException e) { logger.warn("The key file not found: " + e.getMessage()); } dataBytes = saslServer.dataProcess(keyHexString.getBytes(), true); //Client site: if ""'s wraped return or just return "", it will throw new Exception("Invalid key length...") param.setData(dataBytes); } else { param.setData("".getBytes()); logger.warn("Abnormal behavior! saslServer is still in Auth Processing."); } return param; }
From source file:com.qcadoo.maven.plugins.validator.ValidatorMojo.java
public void grepFile(final File file, final String re) throws MojoFailureException { getLog().info("Validating file " + file + " with pattern '" + re + "'"); InputStream in = null;//from w w w . j a v a2 s. c o m InputStreamReader isr = null; BufferedReader data = null; try { in = new FileInputStream(file); isr = new InputStreamReader(in); data = new BufferedReader(isr); String line = data.readLine(); while (line != null) { if (line.contains(re)) { throw new MojoFailureException("File: " + file + " contains a com.qcadoo.mes.internal import which is not permitted. Please use the API instead."); } line = data.readLine(); } } catch (FileNotFoundException e) { getLog().error(e.getMessage()); } catch (IOException e) { getLog().error(e.getMessage()); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(isr); IOUtils.closeQuietly(data); } }
From source file:it.infodreams.syncpath.commands.Commander.java
public void parseArgs(String[] args) { CommandLineParser parser = new BasicParser(); Packager packager = new Packager(); try {/*from ww w . j ava2s .c o m*/ CommandLine line = parser.parse(options, args); if (line.hasOption("split-size")) { long size = 0; if (line.hasOption("split-size")) { size = Long.parseLong(line.getOptionValue("split-size")); } else { ErrorManager.getInstance().error("Value expected for parameter 'split-size'", ErrorLevel.SEVERE); } packager.setPackageSplitSize(size); } if (line.hasOption("verbose")) { LogManager.getInstance().setVerbosityLevel(LogManager.LOG_LEVEL_2); } if (line.hasOption("help") || args.length == 0) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("SyncPath", options); } else if (line.hasOption("scan")) { String path = null; String reportFileName = null; if (line.hasOption("source-path")) { path = line.getOptionValue("source-path"); } else { ErrorManager.getInstance().error( "Parameter '--scan' needs a source path to perform its operation", ErrorLevel.SEVERE); } if (line.hasOption("report")) { reportFileName = line.getOptionValue("report"); } else { ErrorManager.getInstance().error( "Parameter '--scan' needs a report filename to perform its operation", ErrorLevel.SEVERE); } packager.scanPath(path, reportFileName); } else if (line.hasOption("pack")) { String sourcePath = null; String destPath = null; String reportFileName = null; if (line.hasOption("source-path")) { sourcePath = line.getOptionValue("source-path"); } else { ErrorManager.getInstance().error( "Parameter '--pack' needs a source path to perform its operation", ErrorLevel.SEVERE); } if (line.hasOption("dest-path")) { destPath = line.getOptionValue("dest-path"); } else { ErrorManager.getInstance().error( "Parameter '--pack' needs a source path to perform its operation", ErrorLevel.SEVERE); } if (line.hasOption("report")) { reportFileName = line.getOptionValue("report"); } else { ErrorManager.getInstance().error( "Parameter '--pack' needs a report filename to perform its operation", ErrorLevel.SEVERE); } Report report; try { report = Report.loadFromFile(reportFileName); packager.packFiles(report, sourcePath, destPath); } catch (FileNotFoundException ex) { ErrorManager.getInstance().error(ex.getMessage(), ErrorLevel.SEVERE); } } else if (line.hasOption("unpack")) { } } catch (ParseException ex) { ErrorManager.getInstance().error(ex.getMessage(), ErrorLevel.SEVERE); } }