List of usage examples for java.io FileNotFoundException toString
public String toString()
From source file:main.MainClass.java
private static String[] InternalFilesForSupToRepSync() { Integer index = 104;// ww w .jav a 2s .c om BufferedReader fileReader = null; String fileToParse = "./Files/TestFiles/SupToRepSync/MEDCServer/DC/JSONResponse_"; String fileToParseNew = fileToParse + 1 + ".json"; try { String line = ""; //Read the file line by line int i = 1; JSONArray test = new JSONArray(); while (i <= index) { String output = ""; fileToParseNew = fileToParse + i + ".json"; try { fileReader = new BufferedReader(new FileReader(fileToParseNew)); } catch (FileNotFoundException ex) { loggerObj.log(Level.INFO, "Error in reading MEMDM server files from internal file" + fileToParseNew + "Exception is: " + ex.toString()); } while ((line = fileReader.readLine()) != null) { //Get all tokens available in line output += line; //System.out.print(line); } JSONParser parser = new JSONParser(); try { JSONObject json = (JSONObject) parser.parse(output); test.add(json); } catch (ParseException ex) { loggerObj.log(Level.INFO, "Error in parsing MEMDM server files from internal file" + fileToParseNew); } i++; } } catch (IOException ex) { loggerObj.log(Level.INFO, "Error in reading MEMDM server files from internal files" + fileToParseNew); return null; } finally { try { fileReader.close(); } catch (IOException ex) { loggerObj.log(Level.INFO, "Error in closing the fileReader while closing the file" + fileToParseNew); } } return new String[] { fileToParse, index.toString() }; }
From source file:main.MainClass.java
private static String[] InternalFilesForIssMgrRprts(String folderToReadResponse) { loggerObj.log(Level.INFO, "Inside InternalFilesForIssMgrRprts method"); Integer index = 48;//w ww . j av a2s. co m BufferedReader fileReader = null; String fileToParse = folderToReadResponse + "/JSONResponse_"; loggerObj.log(Level.INFO, "Going to read internally files(" + fileToParse + 1 + ".json to " + fileToParse + index + ".json" + ") from folder " + folderToReadResponse + ""); String fileToParseNew = fileToParse + 1 + ".json"; try { String line = ""; //Read the file line by line int i = 1; while (i <= index) { String output = ""; fileToParseNew = fileToParse + i + ".json"; try { fileReader = new BufferedReader(new FileReader(fileToParseNew)); } catch (FileNotFoundException ex) { loggerObj.log(Level.INFO, "Error in reading MEMDM server files from internal file" + fileToParseNew + "Exception is: " + ex.toString()); } while ((line = fileReader.readLine()) != null) { //Get all tokens available in line output += line; //System.out.print(line); } JSONParser parser = new JSONParser(); try { parser.parse(output); } catch (ParseException ex) { loggerObj.log(Level.INFO, "Error in parsing MEMDM server files from internal file" + fileToParseNew); } i++; } } catch (IOException ex) { loggerObj.log(Level.INFO, "Error in reading MEMDM server files from internal files" + fileToParseNew); return null; } finally { try { fileReader.close(); } catch (IOException ex) { loggerObj.log(Level.INFO, "Error in closing the fileReader while closing the file" + fileToParseNew); } } return new String[] { fileToParse, index.toString() }; }
From source file:org.kepler.util.AuthNamespace.java
/** * Read in the Authority and Namespace from the AuthorizedNamespace file. *//* w ww .ja va 2 s .c o m*/ public void refreshAuthNamespace() { if (isDebugging) log.debug("refreshAuthNamespace()"); try { InputStream is = null; ObjectInput oi = null; try { is = new FileInputStream(_anFileName); oi = new ObjectInputStream(is); Object newObj = oi.readObject(); String theString = (String) newObj; int firstColon = theString.indexOf(':'); setAuthority(theString.substring(0, firstColon)); setNamespace(theString.substring(firstColon + 1)); } finally { if (oi != null) { oi.close(); } if (is != null) { is.close(); } } } catch (FileNotFoundException e) { log.error(_saveFileName + " file was not found: " + _anFileName); e.printStackTrace(); } catch (IOException e) { log.error("Unable to create ObjectInputStream"); e.printStackTrace(); } catch (ClassNotFoundException e) { log.error("Unable to read from ObjectInput"); e.printStackTrace(); } catch (Exception e) { log.error(e.toString()); e.printStackTrace(); } if (isDebugging) { log.debug("Instance Authority: " + getAuthority()); log.debug("Instance Namespace: " + getNamespace()); log.debug("Instance AuthNamespace: " + getAuthNamespace()); log.debug("Instance Hash Value: " + getFileNameForm()); } }
From source file:org.apache.hadoop.hive.ql.exec.ACLTask.java
private int showGroup(Hive db, showGroupsDesc sGD) throws HiveException { List<String> groups = null; if (sGD.getPattern() != null) { LOG.info("pattern: " + sGD.getPattern()); groups = db.getGroups(sGD.getPattern()); LOG.info("results : " + groups.size()); } else// w ww . j av a 2 s . co m groups = db.getGroups(".*"); try { FileSystem fs = sGD.getResFile().getFileSystem(conf); DataOutput outStream = (DataOutput) fs.create(sGD.getResFile()); SortedSet<String> sortedTbls = new TreeSet<String>(groups); Iterator<String> iterTbls = sortedTbls.iterator(); while (iterTbls.hasNext()) { outStream.writeBytes(iterTbls.next()); outStream.write(terminator); } ((FSDataOutputStream) outStream).close(); } catch (FileNotFoundException e) { LOG.warn("show groups: " + StringUtils.stringifyException(e)); if (SessionState.get() != null) SessionState.get().ssLog("show groups: " + StringUtils.stringifyException(e)); return 1; } catch (IOException e) { LOG.warn("show groups: " + StringUtils.stringifyException(e)); if (SessionState.get() != null) SessionState.get().ssLog("show groups: " + StringUtils.stringifyException(e)); return 1; } catch (Exception e) { throw new HiveException(e.toString()); } return 0; }
From source file:it.infn.ct.SimpleToscaInterface.java
/** * Read TOSCA resource information json file and stores data * in RuntimeData.//from ww w . j a v a2s .c o m */ public final void saveResourceData() { String infoFilePath = getInfoFilePath(); try { InputStream isInfo = new FileInputStream(infoFilePath); String jsonTxtInfo = IOUtils.toString(isInfo); JSONObject jsonResDesc = (JSONObject) new JSONObject(jsonTxtInfo); LOG.debug("Loaded resource information json:" + LS + jsonResDesc); // "ip":"158.42.105.6" String infoIP = String.format("%s", jsonResDesc.getString("ip")); LOG.debug("info_ip: '" + infoIP + "'"); toscaCommand.setRunTimeData("simple_tosca_ip", infoIP, "Resource IP address", "", ""); // "port":22 String infoSSHPort = String.format("%s", "" + jsonResDesc.getInt("port")); LOG.debug("info_sshport: '" + infoSSHPort + "'"); toscaCommand.setRunTimeData("simple_tosca_sshport", infoSSHPort, "Resource ssh port address", "", ""); // "username":"root" String infoSSHUsername = String.format("%s", jsonResDesc.getString("username")); LOG.debug("info_sshusername: '" + infoSSHUsername + "'"); toscaCommand.setRunTimeData("simple_tosca_sshusername", infoSSHUsername, "Resource ssh username", "", ""); // "password":"Vqpx3Hm4" String infoSSHPassword = String.format("%s", jsonResDesc.getString("password")); LOG.debug("info_sshpassword: '" + infoSSHPassword + "'"); toscaCommand.setRunTimeData("simple_tosca_sshpassword", infoSSHPassword, "Resource ssh user password", "", ""); // "toscaId":"13da6aa0-d5a4-415b-ad8b-29ded3d4d006" String infoToscaId = String.format("%s", jsonResDesc.getString("tosca_id")); LOG.debug("info_tosca_id: '" + infoToscaId + "'"); toscaCommand.setRunTimeData("simple_tosca_id", infoToscaId, "TOSCA resource UUID", "", ""); // "job_id": // "6f4d8d6c-c879-45aa-9d16-c82ca04688ce#\ // 13da6aa0-d5a4-415b-ad8b-29ded3d4d006" String infoJobId = String.format("%s", jsonResDesc.getString("job_id")); LOG.debug("info_job_id: '" + infoJobId + "'"); toscaCommand.setRunTimeData("simple_tosca_jobid", infoJobId, "JSAGA job identifier", "", ""); LOG.debug("Successfully stored all resource data " + "in RunTimeData for task: '" + toscaCommand.getTaskId() + "'"); } catch (FileNotFoundException ex) { LOG.error("File not found: '" + infoFilePath + "'"); } catch (IOException ex) { LOG.error("I/O Exception reading file: '" + infoFilePath + "'"); } catch (Exception ex) { LOG.error("Caught exception: '" + ex.toString() + "'"); } }
From source file:cn.dacas.providers.downloads.DownloadThread.java
/** * Prepare the destination file to receive data. If the file already exists, * we'll set up appropriately for resumption. *///w w w. j ava 2 s . co m private void setupDestinationFile(State state, InnerState innerState) throws StopRequest { if (!TextUtils.isEmpty(state.mFilename)) { // only true if we've already // run a thread for this // download if (!Helpers.isFilenameValid(state.mFilename)) { // this should never happen throw new StopRequest(Downloads.STATUS_FILE_ERROR, "found invalid internal destination filename"); } // We're resuming a download that got interrupted File f = new File(state.mFilename); if (f.exists()) { long fileLength = f.length(); if (fileLength == 0) { // The download hadn't actually started, we can restart from // scratch f.delete(); state.mFilename = null; } else if (mInfo.mETag == null && !mInfo.mNoIntegrity) { // This should've been caught upon failure f.delete(); throw new StopRequest(Downloads.STATUS_CANNOT_RESUME, "Trying to resume a download that can't be resumed"); } else { // All right, we'll be able to resume this download try { state.mStream = new FileOutputStream(state.mFilename, true); } catch (FileNotFoundException exc) { throw new StopRequest(Downloads.STATUS_FILE_ERROR, "while opening destination for resuming: " + exc.toString(), exc); } innerState.mBytesSoFar = (int) fileLength; if (mInfo.mTotalBytes != -1) { innerState.mHeaderContentLength = Long.toString(mInfo.mTotalBytes); } innerState.mHeaderETag = mInfo.mETag; innerState.mContinuingDownload = true; } } } if (state.mStream != null && mInfo.mDestination == Downloads.DESTINATION_EXTERNAL) { closeDestination(state); } }
From source file:com.kong.zxreader.down.downloads.DownloadThread.java
/** * Prepare the destination file to receive data. If the file already exists, * we'll set up appropriately for resumption. */// w ww. ja va2 s .co m private void setupDestinationFile(State state, InnerState innerState) throws StopRequest { if (!TextUtils.isEmpty(state.mFilename)) { // only true if we've already // run a thread for this // download if (!DownHelpers.isFilenameValid(state.mFilename)) { // this should never happen throw new StopRequest(Downloads.STATUS_FILE_ERROR, "found invalid internal destination filename"); } // We're resuming a download that got interrupted File f = new File(state.mFilename); if (f.exists()) { long fileLength = f.length(); if (fileLength == 0) { // The download hadn't actually started, we can restart from // scratch f.delete(); state.mFilename = null; } else if (mInfo.mETag == null && !mInfo.mNoIntegrity) { // This should've been caught upon failure f.delete(); throw new StopRequest(Downloads.STATUS_CANNOT_RESUME, "Trying to resume a download that can't be resumed"); } else { // All right, we'll be able to resume this download try { state.mStream = new FileOutputStream(state.mFilename, true); } catch (FileNotFoundException exc) { throw new StopRequest(Downloads.STATUS_FILE_ERROR, "while opening destination for resuming: " + exc.toString(), exc); } innerState.mBytesSoFar = (int) fileLength; if (mInfo.mTotalBytes != -1) { innerState.mHeaderContentLength = Long.toString(mInfo.mTotalBytes); } innerState.mHeaderETag = mInfo.mETag; innerState.mContinuingDownload = true; } } } if (state.mStream != null && mInfo.mDestination == Downloads.DESTINATION_EXTERNAL) { closeDestination(state); } }
From source file:com.seo.downloadproviders.downloads.DownloadThread.java
/** * Prepare the destination file to receive data. If the file already exists, * we'll set up appropriately for resumption. *///from w ww . jav a 2 s .co m private void setupDestinationFile(State state, InnerState innerState) throws StopRequest { if (!TextUtils.isEmpty(state.mFilename)) { // only true if we've already // run a thread for this // download if (!Helpers.isFilenameValid(state.mFilename)) { // this should never happen throw new StopRequest(Downloads.STATUS_FILE_ERROR, "found invalid internal destination filename"); } // We're resuming a download that got interrupted File f = new File(state.mFilename); if (f.exists()) { long fileLength = f.length(); if (fileLength == 0) { // The download hadn't actually started, we can restart from // scratch f.delete(); state.mFilename = null; // begin modify // } // else if (mInfo.mETag == null && !mInfo.mNoIntegrity) { // // This should've been caught upon failure // f.delete(); // throw new StopRequest(Downloads.STATUS_CANNOT_RESUME, // "Trying to resume a download that can't be resumed"); // end modify } else { // All right, we'll be able to resume this download try { state.mStream = new FileOutputStream(state.mFilename, true); } catch (FileNotFoundException exc) { throw new StopRequest(Downloads.STATUS_FILE_ERROR, "while opening destination for resuming: " + exc.toString(), exc); } innerState.mBytesSoFar = (int) fileLength; if (mInfo.mTotalBytes != -1) { innerState.mHeaderContentLength = Long.toString(mInfo.mTotalBytes); } innerState.mHeaderETag = mInfo.mETag; innerState.mContinuingDownload = true; } } } if (state.mStream != null && mInfo.mDestination == Downloads.DESTINATION_EXTERNAL) { closeDestination(state); } }
From source file:com.example.download.DownloadThread.java
/** * Prepare the destination file to receive data. If the file already exists, we'll set up * appropriately for resumption./*from w ww . j a v a 2s. c o m*/ */ private void setupDestinationFile(State state, InnerState innerState) throws StopRequest { if (!TextUtils.isEmpty(state.mFilename)) { // only true if we've already run a thread for this download if (!Helper.isFilenameValid(state.mFilename, state.mSourceType)) { // this should never happen throw new StopRequest(DownloadManager.Impl.STATUS_FILE_ERROR, "found invalid internal destination filename"); } // We're resuming a download that got interrupted File f = new File(state.mFilename); if (f.exists()) { long fileLength = f.length(); if (fileLength == 0) { // The download hadn't actually started, we can restart from scratch f.delete(); state.mFilename = null; } else if (mInfo.mETag == null) { // This should've been caught upon failure f.delete(); throw new StopRequest(DownloadManager.Impl.STATUS_CANNOT_RESUME, "Trying to resume a download that can't be resumed"); } else { // All right, we'll be able to resume this download try { state.mStream = new FileOutputStream(state.mFilename, true); FileInputStream fis = new FileInputStream(state.mFilename); DigestInputStream dis = new DigestInputStream(fis, state.mDigester); byte[] buffer = new byte[8192]; while (dis.read(buffer) != -1) { // read the digest } dis.close(); fis.close(); } catch (FileNotFoundException exc) { throw new StopRequest(DownloadManager.Impl.STATUS_FILE_ERROR, "while opening destination for resuming: " + exc.toString(), exc); } catch (IOException e) { throw new StopRequest(DownloadManager.Impl.STATUS_FILE_ERROR, "while opening destination for resuming: " + e.toString(), e); } innerState.mBytesSoFar = (int) fileLength; if (mInfo.mTotalBytes != -1) { innerState.mHeaderContentLength = Long.toString(mInfo.mTotalBytes); } innerState.mHeaderETag = mInfo.mETag; innerState.mContinuingDownload = true; } } } if (state.mStream != null && mInfo.mDestination == DownloadManager.Impl.DESTINATION_EXTERNAL) { closeDestination(state); } }