List of usage examples for java.io FileNotFoundException getMessage
public String getMessage()
From source file:com.ctriposs.rest4j.tools.idlcheck.Rest4JResourceModelCompatibilityChecker.java
/** * Check backwards compatibility between two idl (.restspec.json) files. * * @param prevRestspecPath previously existing idl file * @param currRestspecPath current idl file * @param compatLevel compatibility level which affects the return value * @return true if the check result conforms the compatibility level requirement * e.g. false if backwards compatible changes are found but the level is equivalent *///from w ww . j av a2 s. c o m public boolean check(String prevRestspecPath, String currRestspecPath, CompatibilityLevel compatLevel) { _prevRestspecPath = prevRestspecPath; _currRestspecPath = currRestspecPath; Stack<Object> path = new Stack<Object>(); path.push(""); ResourceSchema prevRec = null; ResourceSchema currRec = null; try { prevRec = _codec.readResourceSchema(new FileInputStream(prevRestspecPath)); } catch (FileNotFoundException e) { _infoMap.addRestSpecInfo(CompatibilityInfo.Type.RESOURCE_NEW, path, currRestspecPath); } catch (IOException e) { _infoMap.addRestSpecInfo(CompatibilityInfo.Type.OTHER_ERROR, path, e.getMessage()); } try { currRec = _codec.readResourceSchema(new FileInputStream(currRestspecPath)); } catch (FileNotFoundException e) { _infoMap.addRestSpecInfo(CompatibilityInfo.Type.RESOURCE_MISSING, path, prevRestspecPath); } catch (Exception e) { _infoMap.addRestSpecInfo(CompatibilityInfo.Type.OTHER_ERROR, path, e.getMessage()); } if (prevRec == null || currRec == null) { return _infoMap.isCompatible(compatLevel); } final DataSchemaResolver resolver; if (_resolverPath == null) { resolver = new DefaultDataSchemaResolver(); } else { resolver = new XmlFileDataSchemaResolver(SchemaParserFactory.instance(), _resolverPath); } ResourceCompatibilityChecker checker = new ResourceCompatibilityChecker(prevRec, resolver, currRec, resolver); boolean check = checker.check(compatLevel); _infoMap.addAll(checker.getInfoMap()); return check; }
From source file:flex.webtier.server.j2ee.MxmlServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try {//from w w w .j a v a2s . c o m // encoding must be set before any access to request parameters request.setCharacterEncoding("UTF-8"); MxmlContext context = new MxmlContext(); context.setRequest(request); context.setResponse(response); context.setServletContext(getServletContext()); context.setPageTitle(request.getServletPath()); setupMxmlContextKeys(getServletContext(), context, request); context.setDetectionSettings(DetectionSettingsFactory.getInstance(request.getContextPath())); context.setHistorySettings(HistorySettingsFactory.getInstance(request.getContextPath())); if (!ServiceFactory.getLicenseService().isMxmlCompileEnabled()) { response.sendError(481, "The current license does not support this feature."); ServiceFactory.getLogger().logError( "The current license does not support this feature. request=" + request.getServletPath()); return; } if (isObjectRequest(request)) { if (request.getParameter("w") != null) { context.setWidth(request.getParameter("w")); } else { context.setWidth("100%"); } if (request.getParameter("h") != null) { context.setHeight(request.getParameter("h")); } else { context.setHeight("100%"); } objectFilterChain.invoke(context); } else { PathResolver.setThreadLocalPathResolver(new ServletPathResolver(getServletContext())); flex2.compiler.common.PathResolver resolver = new flex2.compiler.common.PathResolver(); resolver.addSinglePathResolver( new flex.webtier.server.j2ee.ServletPathResolver(getServletContext())); resolver.addSinglePathResolver(LocalFilePathResolver.getSingleton()); resolver.addSinglePathResolver(URLPathResolver.getSingleton()); ThreadLocalToolkit.setPathResolver(resolver); // set up for localizing messages LocalizationManager localizationManager = new LocalizationManager(); localizationManager.addLocalizer(new XLRLocalizer()); localizationManager.addLocalizer(new ResourceBundleLocalizer()); ThreadLocalToolkit.setLocalizationManager(localizationManager); setupCompileEventLogger(context, request); setupSourceCodeLoader(context); filterChain.invoke(context); } } catch (FileNotFoundException fnfe) { // return an error page HttpCache.setCacheHeaders(false, 0, -1, response); response.sendError(HttpServletResponse.SC_NOT_FOUND, fnfe.getMessage()); if (logCompilerErrors) { ServiceFactory.getLogger().logError(fnfe.getMessage(), fnfe); } } catch (Throwable t) { // return an error page ServiceFactory.getLogger().logError("Unknown error " + request.getServletPath() + ": " + t.getMessage(), t); throw new ServletException(t); } finally { ServletUtils.clearThreadLocals(); } }
From source file:at.tuwien.minimee.registry.ToolRegistry.java
private void load(String configFile, boolean useAbsoluteLoader) throws IllegalArgumentException { if (useAbsoluteLoader) { InputStream in;/*from ww w .j a va 2 s. c o m*/ try { in = new FileInputStream(new File(configFile)); load(in); } catch (FileNotFoundException e) { e.printStackTrace(); throw new IllegalArgumentException( e.getMessage() + " - maybe caused by wrong filename? check: " + configFile); } } else { load(Thread.currentThread().getContextClassLoader().getResourceAsStream(configFile)); } }
From source file:com.example.cuisoap.agrimac.homePage.machineDetail.driverInfoFragment.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { license_uri = data.getData();// w w w.j a v a 2 s . c o m Log.e("uri", license_uri.toString()); ContentResolver cr = context.getContentResolver(); try { Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(license_uri)); if (requestCode == 1) { //String path=getRealPathFromURI(uri); //System.out.println(path); bitmap = ImageUtils.comp(bitmap); license_pic.setImageBitmap(bitmap); license_pic.setVisibility(View.VISIBLE); license.setVisibility(View.GONE); license_pic.setOnClickListener(myOnClickListener); machineDetailData.driver_license_filepath = ImageUtils.saveMyBitmap(bitmap, null); } } catch (FileNotFoundException e) { Log.e("Exception", e.getMessage(), e); } } else { Toast.makeText(context, "?", Toast.LENGTH_SHORT).show(); } super.onActivityResult(requestCode, resultCode, data); }
From source file:com.linkedin.restli.tools.idlcheck.RestLiResourceModelCompatibilityChecker.java
/** * Check backwards compatibility between two idl (.restspec.json) files. * * @param prevRestspecPath previously existing idl file * @param currRestspecPath current idl file * @param compatLevel compatibility level which affects the return value * @return true if the check result conforms the compatibility level requirement * e.g. false if backwards compatible changes are found but the level is equivalent *//*from www. ja va2 s .co m*/ public boolean check(String prevRestspecPath, String currRestspecPath, CompatibilityLevel compatLevel) { _prevRestspecPath = prevRestspecPath; _currRestspecPath = currRestspecPath; Stack<Object> path = new Stack<Object>(); path.push(""); ResourceSchema prevRec = null; ResourceSchema currRec = null; try { prevRec = _codec.readResourceSchema(new FileInputStream(prevRestspecPath)); } catch (FileNotFoundException e) { _infoMap.addRestSpecInfo(CompatibilityInfo.Type.RESOURCE_NEW, path, currRestspecPath); } catch (IOException e) { _infoMap.addRestSpecInfo(CompatibilityInfo.Type.OTHER_ERROR, path, e.getMessage()); } try { currRec = _codec.readResourceSchema(new FileInputStream(currRestspecPath)); } catch (FileNotFoundException e) { _infoMap.addRestSpecInfo(CompatibilityInfo.Type.RESOURCE_MISSING, path, prevRestspecPath); } catch (Exception e) { _infoMap.addRestSpecInfo(CompatibilityInfo.Type.OTHER_ERROR, path, e.getMessage()); } if (prevRec == null || currRec == null) { return _infoMap.isCompatible(compatLevel); } final DataSchemaResolver resolver; if (_resolverPath == null) { resolver = new DefaultDataSchemaResolver(); } else { resolver = new FileDataSchemaResolver(SchemaParserFactory.instance(), _resolverPath); } ResourceCompatibilityChecker checker = new ResourceCompatibilityChecker(prevRec, resolver, currRec, resolver); boolean check = checker.check(compatLevel); _infoMap.addAll(checker.getInfoMap()); return check; }
From source file:com.android.sdklib.internal.repository.DownloadCacheTest.java
public void testMissingResource() throws Exception { // Downloads must fail when using the only-cache strategy and there's nothing in the cache. // In that case, it returns null to indicate the resource is simply not found. // Since the mock implementation always returns a 404 and no stream, there is no // difference between the various cache strategies. mFileOp.reset();/*from www . jav a2 s .c o m*/ NoDownloadCache d1 = new NoDownloadCache(mFileOp, Strategy.ONLY_CACHE); InputStream is1 = d1.openCachedUrl("http://www.example.com/download1.xml", mMonitor); assertNull(is1); assertEquals("", mMonitor.getAllCapturedLogs()); assertTrue(mFileOp.hasRecordedExistingFolder(d1.getCacheRoot())); assertEquals("[]", Arrays.toString(mFileOp.getOutputStreams())); // HTTP-Client's behavior is to return a FNF instead of 404 so we'll try that first mFileOp.reset(); NoDownloadCache d2 = new NoDownloadCache(mFileOp, Strategy.DIRECT); try { d2.openCachedUrl("http://www.example.com/download1.xml", mMonitor); fail("Expected: NoDownloadCache.openCachedUrl should have thrown a FileNotFoundException"); } catch (FileNotFoundException e) { assertEquals("http://www.example.com/download1.xml", e.getMessage()); } assertEquals("", mMonitor.getAllCapturedLogs()); assertEquals("[]", Arrays.toString(mFileOp.getOutputStreams())); // Try again but this time we'll define a 404 reply to test the rest of the code path. mFileOp.reset(); d2.registerResponse("http://www.example.com/download1.xml", 404, null); InputStream is2 = d2.openCachedUrl("http://www.example.com/download1.xml", mMonitor); assertNull(is2); assertEquals("", mMonitor.getAllCapturedLogs()); assertEquals("[]", Arrays.toString(mFileOp.getOutputStreams())); mFileOp.reset(); NoDownloadCache d3 = new NoDownloadCache(mFileOp, Strategy.SERVE_CACHE); d3.registerResponse("http://www.example.com/download1.xml", 404, null); InputStream is3 = d3.openCachedUrl("http://www.example.com/download1.xml", mMonitor); assertNull(is3); assertEquals("", mMonitor.getAllCapturedLogs()); assertEquals("[]", Arrays.toString(mFileOp.getOutputStreams())); mFileOp.reset(); NoDownloadCache d4 = new NoDownloadCache(mFileOp, Strategy.FRESH_CACHE); d4.registerResponse("http://www.example.com/download1.xml", 404, null); InputStream is4 = d4.openCachedUrl("http://www.example.com/download1.xml", mMonitor); assertNull(is4); assertEquals("", mMonitor.getAllCapturedLogs()); assertEquals("[]", Arrays.toString(mFileOp.getOutputStreams())); }
From source file:org.freelectron.leobel.testlwa.models.AlertsFileDataStore.java
@Override public synchronized void loadFromDisk(final AlertManager manager, final ResultListener listener) { sExecutor.execute(new Runnable() { @Override// w w w.ja v a 2 s . co m public void run() { FileReader fis = null; BufferedReader br = null; JsonReader parser = null; ObjectReader reader = ObjectMapperFactory.getObjectReader() .forType(new TypeReference<List<Alert>>() { }); List<Alert> droppedAlerts = new LinkedList<Alert>(); try { fis = new FileReader(ALARM_FILE); br = new BufferedReader(fis); List<Alert> alerts = reader.readValue(br); for (Alert alert : alerts) { // Only add alerts that are within the expiration window if (alert.getScheduledTime() .isAfter(DateTime.now().minusMinutes(MINUTES_AFTER_PAST_ALERT_EXPIRES))) { manager.add(alert, true); } else { droppedAlerts.add(alert); } } // Now that all the valid alerts have been re-added to the alarm manager, // go through and explicitly drop all the alerts that were not added for (Alert alert : droppedAlerts) { manager.drop(alert); } listener.onSuccess(); } catch (FileNotFoundException e) { // This is not a fatal error // The alarm file might not have been created yet listener.onSuccess(); } catch (IOException e) { Log.d("Fail", "Failed to load alerts from disk." + e.getMessage(), e); listener.onFailure(); } finally { IOUtils.closeQuietly(parser); IOUtils.closeQuietly(br); } } }); }
From source file:com.kagubuzz.servlets.UploadServlet.java
/** * Handles the HTTP <code>POST</code> method. * // ww w . ja va 2s .c o m * @param request * servlet request * @param response * servlet response * @throws ServletException * if a servlet-specific error occurs * @throws IOException * if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException { ApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); fileService = (FileService) applicationContext.getBean("fileService"); JavaFileUtilities fileUtils = new JavaFileUtilities(); InputStream is = null; FileOutputStream os = null; Map<String, Object> uploadResult = new HashMap<String, Object>(); ObjectMapper mapper = new ObjectMapper(); //TODO: Mske all these files write to a tmp direcotry for th euploader to be erased when the review button is pushed try { byte[] buffer = new byte[4096]; int bytesRead = 0; // Make sure image file is less than 4 megs if (bytesRead > 1024 * 1024 * 4) throw new FileUploadException(); is = request.getInputStream(); File tmpFile = File.createTempFile("image-", ".jpg"); os = new FileOutputStream(tmpFile); System.out.println("Saving to " + JavaFileUtilities.getTempFilePath()); while ((bytesRead = is.read(buffer)) != -1) os.write(buffer, 0, bytesRead); KaguImage thumbnailImage = new KaguImage(tmpFile); thumbnailImage.setWorkingDirectory(JavaFileUtilities.getTempFilePath()); thumbnailImage.resize(140, 180); File thumbnail = thumbnailImage .saveAsJPG("thumbnail-" + FilenameUtils.removeExtension(tmpFile.getName())); fileService.write(fileUtils.fileToByteArrayOutputStream(tmpFile), tmpFile.getName(), fileService.getTempFilePath()); fileService.write(fileUtils.fileToByteArrayOutputStream(thumbnail), thumbnail.getName(), fileService.getTempFilePath()); response.setStatus(HttpServletResponse.SC_OK); uploadResult.put("success", "true"); uploadResult.put("indexedfilename", fileService.getTempDirectoryURL() + tmpFile.getName()); uploadResult.put("thumbnailfilename", fileService.getTempDirectoryURL() + thumbnail.getName()); } catch (FileNotFoundException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); uploadResult.put("success", "false"); log(UploadServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } catch (IOException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); uploadResult.put("success", "false"); log(UploadServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } catch (FileUploadException e) { response.setStatus(HttpServletResponse.SC_OK); uploadResult.put("success", "false"); uploadResult.put("indexedfilename", "filetobig"); } finally { try { mapper.writeValue(response.getWriter(), uploadResult); os.close(); is.close(); } catch (IOException ignored) { } } }
From source file:com.haulmont.cuba.gui.ScreensHelper.java
protected Map<String, Object> getAvailableScreensMap(Class entityClass, ScreenType filterScreenType) { String key = getScreensCacheKey(entityClass.getName(), getUserLocale(), filterScreenType); Map<String, Object> screensMap = availableScreensCache.get(key); if (screensMap != null) { return screensMap; }//from www . j av a 2 s. c o m Collection<WindowInfo> windowInfoCollection = windowConfig.getWindows(); screensMap = new TreeMap<>(); Set<String> visitedWindowIds = new HashSet<>(); for (WindowInfo windowInfo : windowInfoCollection) { String windowId = windowInfo.getId(); // just skip for now, we assume all versions of screen can operate with the same entity if (visitedWindowIds.contains(windowId)) { continue; } String src = windowInfo.getTemplate(); if (StringUtils.isNotEmpty(src)) { try { Element windowElement = getWindowElement(src); if (windowElement != null) { if (isEntityAvailable(windowElement, entityClass, filterScreenType)) { String caption = getScreenCaption(windowElement, src); caption = getDetailedScreenCaption(caption, windowId); screensMap.put(caption, windowId); } } else { screensMap.put(windowId, windowId); } } catch (FileNotFoundException e) { log.error(e.getMessage()); } } visitedWindowIds.add(windowId); } screensMap = Collections.unmodifiableMap(screensMap); cacheScreens(key, screensMap); return screensMap; }
From source file:com.mbrlabs.mundus.core.project.ProjectManager.java
/** * Loads the project that was open when the user quit the program. * * Does not open open the project./*from w w w. j a v a2 s. c o m*/ * * @return project context of last project */ public ProjectContext loadLastProject() { ProjectRef lastOpenedProject = registry.getLastOpenedProject(); if (lastOpenedProject != null) { try { return loadProject(lastOpenedProject); } catch (FileNotFoundException fnf) { Log.error(fnf.getMessage()); fnf.printStackTrace(); return null; } } return null; }