List of usage examples for java.io FileNotFoundException toString
public String toString()
From source file:org.onebusaway.io.client.request.RequestBase.java
protected <T> T call(Class<T> cls) { ObaApi.SerializationHandler handler = ObaApi.getSerializer(cls); ObaConnection conn = null;// ww w .j a v a2 s .c om try { conn = ObaApi.getDefaultContext().getConnectionFactory().newConnection(mUri); Reader reader; if (mPostData != null) { reader = conn.post(mPostData); } else { int responseCode = conn.getResponseCode(); if (responseCode != HttpURLConnection.HTTP_OK) { return handler.createFromError(cls, responseCode, ""); } reader = conn.get(); } T t = handler.deserialize(reader, cls); if (t == null) { t = handler.createFromError(cls, ObaApi.OBA_INTERNAL_ERROR, "Json error"); } return t; } catch (FileNotFoundException e) { System.err.println(e.toString()); return handler.createFromError(cls, ObaApi.OBA_NOT_FOUND, e.toString()); } catch (IOException e) { System.err.println(e.toString()); return handler.createFromError(cls, ObaApi.OBA_IO_EXCEPTION, e.toString()); } finally { if (conn != null) { conn.disconnect(); } } }
From source file:org.fcrepo.importexport.exporter.Exporter.java
private void exportMembers(final File file) { try {/* www. jav a2s .c o m*/ final Model model = createDefaultModel().read(new FileInputStream(file), null, config.getRdfLanguage()); for (final NodeIterator it = model.listObjectsOfProperty(CONTAINS); it.hasNext();) { export(URI.create(it.nextNode().toString())); } } catch (FileNotFoundException ex) { logger.warn("Unable to parse file: {}", ex.toString()); } }
From source file:org.onebusaway.io.client.request.RequestBase.java
protected <T> T callPostHack(Class<T> cls) { ObaApi.SerializationHandler handler = ObaApi.getSerializer(cls); ObaConnection conn = null;//from ww w . jav a 2 s.com try { conn = ObaApi.getDefaultContext().getConnectionFactory().newConnection(mUri); BufferedReader reader = new BufferedReader(conn.post(mPostData), 8 * 1024); String line; StringBuffer text = new StringBuffer(); while ((line = reader.readLine()) != null) { text.append(line + "\n"); } String response = text.toString(); if (StringUtils.isEmpty(response)) { return handler.createFromError(cls, ObaApi.OBA_OK, "OK"); } else { // {"actionErrors":[],"fieldErrors":{"stopId":["requiredField.stopId"]}} // TODO: Deserialize the JSON and check "fieldErrors" // if this is empty, then it succeeded? Or check for an actual ObaResponse??? return handler.createFromError(cls, ObaApi.OBA_INTERNAL_ERROR, response); } } catch (FileNotFoundException e) { System.err.println(e.toString()); return handler.createFromError(cls, ObaApi.OBA_NOT_FOUND, e.toString()); } catch (IOException e) { System.err.println(e.toString()); return handler.createFromError(cls, ObaApi.OBA_IO_EXCEPTION, e.toString()); } finally { if (conn != null) { conn.disconnect(); } } }
From source file:com.logisima.selenium.server.action.StaticAction.java
@Override public void execute() { this.setContentType(); try {/*w w w . ja v a 2s. c om*/ if (request.getUri().endsWith(".png") | request.getUri().endsWith(".gif")) { File image = new File(documentRoot.getAbsolutePath() + request.getUri()); this.content = ChannelBuffers.copiedBuffer(FileUtils.readFileToByteArray(image)); } else { // Process the request StringBuilder buf = new StringBuilder(); buf.setLength(0); Scanner scanner = null; String fileName = documentRoot.getAbsolutePath() + request.getUri().split("[?]")[0]; String NL = System.getProperty("line.separator"); scanner = new Scanner(new FileInputStream(fileName), "utf-8"); while (scanner.hasNextLine()) { buf.append(scanner.nextLine() + NL); } this.content = ChannelBuffers.copiedBuffer(buf.toString(), CharsetUtil.UTF_8); } } catch (FileNotFoundException e) { this.status = HttpResponseStatus.NOT_FOUND; this.content = ChannelBuffers.copiedBuffer(e.toString(), CharsetUtil.UTF_8); } catch (IOException e) { this.status = HttpResponseStatus.INTERNAL_SERVER_ERROR; this.content = ChannelBuffers.copiedBuffer(e.toString(), CharsetUtil.UTF_8); } }
From source file:org.montanafoodhub.base.get.AdHub.java
protected List<Ad> readFromFile(Context context) { List<Ad> myAdArr = new ArrayList<Ad>(); try {/*from w w w. j a v a 2 s.co m*/ // getItem the time the file was last changed here File myFile = new File(context.getFilesDir() + "/" + fileName); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); String lastRefreshTSStr = sdf.format(myFile.lastModified()); Log.w(HubInit.logTag, "Using file (" + fileName + ") last modified on : " + lastRefreshTSStr); lastRefreshTS = sdf.getCalendar(); // create products from the file here InputStream inputStream = context.openFileInput(fileName); if (inputStream != null) { parseCSV(myAdArr, inputStream); } inputStream.close(); } catch (FileNotFoundException e) { Log.e(HubInit.logTag, "File (" + fileName + ") not found: " + e.toString()); } catch (IOException e) { Log.e(HubInit.logTag, "Can not read file (" + fileName + ") : " + e.toString()); } Log.w(HubInit.logTag, "Number of Ad loaded: " + myAdArr.size()); return myAdArr; }
From source file:org.activiti.osgi.blueprint.BlueprintBasicTest.java
protected InputStream createTestBundleWithProcessDefinition() { try {/* ww w . j av a 2s .c o m*/ return TinyBundles.bundle() .add("OSGI-INF/activiti/example.bpmn20.xml", new FileInputStream(new File("src/test/resources/processes/example.bpmn20.xml"))) .set(Constants.BUNDLE_SYMBOLICNAME, "org.activiti.osgi.example").build(); } catch (FileNotFoundException fnfe) { fail("Failure in createTestBundleWithProcessDefinition " + fnfe.toString()); return null; } }
From source file:com.barcamppenang2013.tabfragment.SponsorFragment.java
private String readFromFile(String fileName) { String ret = ""; try {//w w w . j a v a2s .c o m InputStream inputStream = this.getActivity().openFileInput(fileName); if (inputStream != null) { InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String receiveString = ""; StringBuilder stringBuilder = new StringBuilder(); while ((receiveString = bufferedReader.readLine()) != null) { stringBuilder.append(receiveString); } inputStream.close(); ret = stringBuilder.toString(); } } catch (FileNotFoundException e) { Log.e("login activity", "File not found: " + e.toString()); } catch (IOException e) { Log.e("login activity", "Can not read file: " + e.toString()); } return ret; }
From source file:org.activiti.osgi.blueprint.BlueprintBasicTest.java
protected InputStream createTestBundleWithProcessEngineConfiguration() { try {/*from ww w . j a v a 2s.c o m*/ return TinyBundles.bundle() .add("OSGI-INF/blueprint/context.xml", new FileInputStream(new File("src/test/resources/config/context.xml"))) .set(Constants.BUNDLE_SYMBOLICNAME, "org.activiti.osgi.config") .set(Constants.DYNAMICIMPORT_PACKAGE, "*").build(); } catch (FileNotFoundException fnfe) { fail("Failure in createTestBundleWithProcessEngineConfiguration " + fnfe.toString()); return null; } }
From source file:org.flowable.osgi.blueprint.BlueprintBasicTest.java
protected InputStream createTestBundleWithTask() { try {/*from www . jav a2 s .com*/ return TinyBundles.bundle() .add("OSGI-INF/blueprint/context.xml", new FileInputStream(new File("src/test/resources/task/context.xml"))) .add(SimpleBean.class).add(ActivityBehaviourBean.class) .set(Constants.BUNDLE_SYMBOLICNAME, "org.flowable.osgi.task") .set(Constants.DYNAMICIMPORT_PACKAGE, "*").build(); } catch (FileNotFoundException fnfe) { fail("Failure in createTestBundleWithTask " + fnfe.toString()); return null; } }
From source file:org.flowable.osgi.blueprint.BlueprintBasicTest.java
protected InputStream createTestBundleWithProcessDefinition() { try {/*from w w w . jav a2 s. co m*/ return TinyBundles.bundle() .add("OSGI-INF/flowable/example.bpmn20.xml", new FileInputStream(new File("src/test/resources/processes/example.bpmn20.xml"))) .set(Constants.BUNDLE_SYMBOLICNAME, "org.flowable.osgi.example").build(); } catch (FileNotFoundException fnfe) { fail("Failure in createTestBundleWithProcessDefinition " + fnfe.toString()); return null; } }