List of usage examples for java.io FileNotFoundException getMessage
public String getMessage()
From source file:dk.dma.ais.utils.aisbus.AisBusLauncher.java
@Override protected void runDaemon(Injector injector) throws Exception { LOG.info("Starting AisBusLauncher with configuration: " + confFile); try {//w ww . j a va2 s . c om aisBus = AisBusFactory.get(confFile); } catch (FileNotFoundException e) { LOG.error(e.getMessage()); return; } LOG.info("Starting AisBus"); aisBus.start(); LOG.info("Starting consumers"); aisBus.startConsumers(); LOG.info("Starting providers"); aisBus.startProviders(); Thread.sleep(2000); while (true) { LOG.debug(StringUtils.leftPad("", 100, '-')); ratePrint(aisBus, null); for (AisBusProvider provider : aisBus.getProviders()) { ratePrint(provider, provider.getName()); if (provider instanceof TcpServerProvider) { for (TcpClient tcpClient : ((TcpServerProvider) provider).getServer().getClients()) { ratePrint(tcpClient); } } } for (AisBusConsumer consumer : aisBus.getConsumers()) { ratePrint(consumer, consumer.getName()); if (consumer instanceof TcpServerConsumer) { for (TcpClient tcpClient : ((TcpServerConsumer) consumer).getServer().getClients()) { ratePrint(tcpClient); } } } LOG.debug(StringUtils.leftPad("", 100, '-')); Thread.sleep(60000); } }
From source file:net.itransformers.idiscover.discoverylisteners.DeviceFileLogger.java
public void handleDevice(String deviceName, RawDeviceData rawData, DiscoveredDeviceData discoveredDeviceData, Resource resource) {/* w ww. j a va 2 s. c om*/ // final String deviceFileName = path + File.separator + "device-data-" + deviceName + ".xml"; final String deviceFileName = "device-data-" + deviceName + ".xml"; OutputStream os = null; try { os = new FileOutputStream(new File(deviceDataPath, deviceFileName)); JaxbMarshalar.marshal(discoveredDeviceData, os, "DiscoveredDevice"); } catch (FileNotFoundException e) { logger.error(e.getMessage(), e); } catch (JAXBException e) { logger.error(e.getMessage(), e); } finally { if (os != null) try { os.close(); } catch (IOException e) { } } byte[] data = rawData.getData(); // final String rawDeviceName = path + File.separator + "raw-data-" + deviceName + ".xml"; final String rawDeviceName = "raw-data-" + deviceName + ".xml"; try { FileUtils.writeStringToFile(new File(rawDataPath, rawDeviceName), new String(data)); } catch (IOException e) { logger.error("Can not log raw data file: " + rawDeviceName, e); } }
From source file:com.intel.cosbench.web.AbstractController.java
@Override public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse res) throws Exception { ModelAndView result;// ww w. jav a 2s . c om try { result = process(req, res); } catch (BadRequestException bre) { return new ModelAndView("400"); } catch (NotFoundException nfe) { return new ModelAndView("404"); } catch (FileNotFoundException fnfe) { return new ModelAndView("404", "resource", fnfe.getMessage()); } catch (Exception e) { StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); return new ModelAndView("500", "cause", writer.toString()); } String showDetails = req.getParameter("showDetails"); result.addObject("showDetails", Boolean.parseBoolean(showDetails)); String perfDetails = req.getParameter("perfDetails"); result.addObject("perfDetails", Boolean.parseBoolean(perfDetails)); String showErrorStatistics = req.getParameter("showErrorStatistics"); result.addObject("showErrorStatistics", Boolean.parseBoolean(showErrorStatistics)); return result; }
From source file:org.zilverline.extractors.TestHTMLExtractor.java
public void testGetContentAsInputStream() { try {/*w w w. j a v a 2 s . co m*/ HTMLExtractor tex = new HTMLExtractor(); InputStream is = new FileInputStream("test\\data\\test.html"); String txt = tex.getContent(is); assertNotNull(txt); log.debug(txt.trim()); assertTrue(txt.length() > 0); assertTrue(txt.trim().endsWith("Dit is een test in een HTML document.")); assertTrue(StringUtils.countOccurrencesOf(txt, "test") > 0); } catch (FileNotFoundException e) { fail(e.getMessage()); } }
From source file:com.npower.unicom.sync.firmware.FirmwareFileSyncItemWriter.java
@Override protected String convertToString(SyncItem item) { StringBuffer buf = new StringBuffer(); if (item == null) { return buf.toString(); }//from ww w.java2 s. c o m buf.append(item.getId()); buf.append('\t'); buf.append(item.getAction().getValue()); buf.append('\t'); if (item instanceof FirmwareSyncItem) { FirmwareSyncItem newitem = (FirmwareSyncItem) item; buf.append(newitem.getManufacturer()); buf.append('\t'); buf.append(newitem.getModel()); buf.append('\t'); buf.append(newitem.getFromVersion()); buf.append('\t'); buf.append(newitem.getToVersion()); buf.append('\t'); buf.append(newitem.getFirmwareName()); buf.append(".fw"); buf.append('\n'); File fwFile = new File(this.getFile().getParent(), newitem.getId() + ".fw"); try { FileOutputStream out = new FileOutputStream(fwFile); out.write(newitem.getBytes()); out.close(); } catch (FileNotFoundException e) { log.error(e.getMessage(), e); } catch (IOException e) { log.error(e.getMessage(), e); } } return buf.toString(); }
From source file:com.aurel.track.exchange.docx.exporter.AssembleWordprocessingMLPackage.java
/** * Add the actual values of custom xml//from www.ja v a2s . c o m * @param wordprocessingMLPackage * @param workItemBean * @param personID * @param locale */ private static void addCustomXMLPart(WordprocessingMLPackage wordprocessingMLPackage, TWorkItemBean workItemBean, Integer personID, Locale locale) { try { Document customXMLDocument = CustomXML.convertToDOM(workItemBean, personID, locale); if (LOGGER.isDebugEnabled()) { File file = new File(DocxTemplateBL.getWordTemplatesDir() + "Custom.xml"); if (file.exists()) { file.delete(); } FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(file); } catch (FileNotFoundException e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } CustomXML.convertToXml(fileOutputStream, customXMLDocument); } Docx4J.bind(wordprocessingMLPackage, customXMLDocument, Docx4J.FLAG_BIND_INSERT_XML | Docx4J.FLAG_BIND_BIND_XML); } catch (Docx4JException e) { LOGGER.info("Binding failed with Docx4JException " + e.getMessage(), e); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } catch (Exception e) { LOGGER.info("Binding failed with " + e.getMessage(), e); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } }
From source file:net.shopxx.plugin.ossStorage.OssStoragePlugin.java
@Override public void upload(String path, File file, String contentType) { PluginConfig pluginConfig = getPluginConfig(); if (pluginConfig != null) { String endpoint = pluginConfig.getAttribute("endpoint"); String accessId = pluginConfig.getAttribute("accessId"); String accessKey = pluginConfig.getAttribute("accessKey"); String bucketName = pluginConfig.getAttribute("bucketName"); InputStream inputStream = null; try {// w w w. j ava 2 s . c o m inputStream = new BufferedInputStream(new FileInputStream(file)); OSSClient ossClient = new OSSClient(endpoint, accessId, accessKey); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentType(contentType); objectMetadata.setContentLength(file.length()); ossClient.putObject(bucketName, StringUtils.removeStart(path, "/"), inputStream, objectMetadata); } catch (FileNotFoundException e) { throw new RuntimeException(e.getMessage(), e); } finally { IOUtils.closeQuietly(inputStream); } } }
From source file:org.dspace.app.webui.cris.controller.jdyna.ResearcherTabImageController.java
@Override public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse response) throws Exception { String idString = req.getPathInfo(); String[] pathInfo = idString.split("/", 3); String tabId = pathInfo[2];//from w w w . ja v a2s . co m String contentType = ""; String ext = ""; Tab tab = applicationService.get(Tab.class, Integer.parseInt(tabId)); ext = tab.getExt(); contentType = tab.getMime(); if (ext != null && !ext.isEmpty() && contentType != null && !contentType.isEmpty()) { File image = new File( tab.getFileSystemPath() + File.separatorChar + AFormTabController.DIRECTORY_TAB_ICON + File.separatorChar + AFormTabController.PREFIX_TAB_ICON + tabId + "." + ext); InputStream is = null; try { is = new FileInputStream(image); response.setContentType(contentType); // Response length response.setHeader("Content-Length", String.valueOf(image.length())); Utils.bufferedCopy(is, response.getOutputStream()); is.close(); response.getOutputStream().flush(); } catch (FileNotFoundException not) { log.error(not.getMessage()); response.sendError(HttpServletResponse.SC_NOT_FOUND); } finally { if (is != null) { is.close(); } } } return null; }
From source file:com.ikon.util.cl.FilesystemClassLoader.java
/** * Get resource input stream/*from w ww . j ava 2s . co m*/ */ @Override public InputStream getResourceAsStream(String name) { log.debug("getResourceAsStream({})", name); File fr = new File(file, name); try { if (fr.exists() && fr.canRead()) { return new FileInputStream(fr); } } catch (FileNotFoundException e) { log.error(e.getMessage(), e); } return null; }
From source file:net.sf.j2ep.test.PostTest.java
public void beginSendMultipart(WebRequest theRequest) { theRequest.setURL("localhost:8080", "/test", "/POST/multipart.jsp", null, null); theRequest.addParameter("tmp", "", WebRequest.POST_METHOD); try {/*from w w w. j a v a 2 s . c o m*/ PostMethod post = new PostMethod(); FilePart filePart = new FilePart("theFile", new File("WEB-INF/classes/net/sf/j2ep/test/POSTdata")); StringPart stringPart = new StringPart("testParam", "123456"); Part[] parts = new Part[2]; parts[0] = stringPart; parts[1] = filePart; MultipartRequestEntity reqEntitiy = new MultipartRequestEntity(parts, post.getParams()); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); reqEntitiy.writeRequest(outStream); theRequest.setUserData(new ByteArrayInputStream(outStream.toByteArray())); theRequest.addHeader("content-type", reqEntitiy.getContentType()); } catch (FileNotFoundException e) { fail("File was not found " + e.getMessage()); } catch (IOException e) { fail("IOException"); e.printStackTrace(); } }