List of usage examples for java.io IOException getStackTrace
public StackTraceElement[] getStackTrace()
From source file:net.sf.taverna.t2.security.credentialmanager.impl.HTTPAuthenticatorIT.java
@AfterClass // Clean up the credentialManagerDirectory we created for testing public static void cleanUp() { if (credentialManagerDirectory.exists()) { try {//from w w w .j a va 2 s. co m FileUtils.deleteDirectory(credentialManagerDirectory); System.out.println( "Deleting Credential Manager's directory: " + credentialManagerDirectory.getAbsolutePath()); } catch (IOException e) { System.out.println(e.getStackTrace()); } } }
From source file:morphy.utils.FileUtils.java
/** * This code was obtained from:/*from www.j a v a 2s. co m*/ * http://www.dreamincode.net/code/snippet1443.htm * * This function will copy files or directories from one location to * another. note that the source and the destination must be mutually * exclusive. This function can not be used to copy a directory to a sub * directory of itself. The function will also have problems if the * destination files already exist. * * @param src * -- A File object that represents the source for the copy * @param dest * -- A File object that represents the destination for the copy. * @throws IOException * if unable to copy. */ public static void copyFiles(File src, File dest) throws IOException { if (src.getName().startsWith(".")) { if (LOG.isDebugEnabled()) { LOG.debug("Ignoring " + src.getAbsolutePath() + " because name started with ."); } return; } // Check to ensure that the source is valid... if (!src.exists()) { throw new IOException("copyFiles: Can not find source: " + src.getAbsolutePath() + "."); } else if (!src.canRead()) { // check to ensure we have rights to the // source... throw new IOException("copyFiles: No right to source: " + src.getAbsolutePath() + "."); } // is this a directory copy? if (src.isDirectory()) { if (!dest.exists()) { // does the destination already exist? // if not we need to make it exist if possible (note this is // mkdirs not mkdir) if (!dest.mkdirs()) { throw new IOException("copyFiles: Could not create direcotry: " + dest.getAbsolutePath() + "."); } if (LOG.isDebugEnabled()) { LOG.debug("Created directory " + dest.getAbsolutePath()); } } // get a listing of files... String list[] = src.list(); // copy all the files in the list. for (String element : list) { File dest1 = new File(dest, element); File src1 = new File(src, element); copyFiles(src1, dest1); } } else { // This was not a directory, so lets just copy the file FileInputStream fin = null; FileOutputStream fout = null; byte[] buffer = new byte[4096]; // Buffer 4K at a time (you can // change this). int bytesRead; try { // open the files for input and output fin = new FileInputStream(src); fout = new FileOutputStream(dest); // while bytesRead indicates a successful read, lets write... while ((bytesRead = fin.read(buffer)) >= 0) { fout.write(buffer, 0, bytesRead); } if (LOG.isDebugEnabled()) { LOG.debug("Copied " + src.getAbsolutePath() + " to " + dest.getAbsolutePath()); } } catch (IOException e) { // Error copying file... IOException wrapper = new IOException("copyFiles: Unable to copy file: " + src.getAbsolutePath() + "to" + dest.getAbsolutePath() + "."); wrapper.initCause(e); wrapper.setStackTrace(e.getStackTrace()); throw wrapper; } finally { // Ensure that the files are closed (if they were open). if (fin != null) { try { fin.close(); } catch (Throwable t) { } } if (fout != null) { try { fout.close(); } catch (Throwable t) { } } } } }
From source file:ly.stealth.punxsutawney.Marathon.java
private static JSONObject sendRequest(String uri, String method, JSONObject json) throws IOException { URL url = new URL(Marathon.url + uri); HttpURLConnection c = (HttpURLConnection) url.openConnection(); try {//from w ww . j a v a2s.c om c.setRequestMethod(method); if (method.equalsIgnoreCase("POST")) { byte[] body = json.toString().getBytes("utf-8"); c.setDoOutput(true); c.setRequestProperty("Content-Type", "application/json"); c.setRequestProperty("Content-Length", "" + body.length); c.getOutputStream().write(body); } return (JSONObject) JSONValue.parse(new InputStreamReader(c.getInputStream(), "utf-8")); } catch (IOException e) { if (c.getResponseCode() == 404 && method.equals("GET")) return null; ByteArrayOutputStream response = new ByteArrayOutputStream(); InputStream err = c.getErrorStream(); if (err == null) throw e; Util.copyAndClose(err, response); IOException ne = new IOException(e.getMessage() + ": " + response.toString("utf-8")); ne.setStackTrace(e.getStackTrace()); throw ne; } finally { c.disconnect(); } }
From source file:tectonicus.util.FileUtils.java
/** * This function will copy files or directories from one location to * another. note that the source and the destination must be mutually * exclusive. This function can not be used to copy a directory to a sub * directory of itself. The function will also have problems if the * destination files already exist./*from www. j a va 2s .com*/ * * @param src * -- A File object that represents the source for the copy * @param dest * -- A File object that represnts the destination for the copy. * @throws IOException * if unable to copy. */ public static void copyFiles(File src, File dest, Set<String> excludeExtensions) throws IOException { // Check to ensure that the source is valid... if (!src.exists()) { throw new IOException("copyFiles: Can not find source: " + src.getAbsolutePath() + "."); } else if (!src.canRead()) { // check to ensure we have rights to the source... throw new IOException("copyFiles: No right to source: " + src.getAbsolutePath() + "."); } // is this a directory copy? if (src.isDirectory()) { if (!dest.exists()) { // does the destination already exist? // if not we need to make it exist if possible (note this is // mkdirs not mkdir) if (!dest.mkdirs()) { throw new IOException("copyFiles: Could not create direcotry: " + dest.getAbsolutePath() + "."); } } // get a listing of files... String list[] = src.list(); // copy all the files in the list. for (int i = 0; i < list.length; i++) { File dest1 = new File(dest, list[i]); File src1 = new File(src, list[i]); copyFiles(src1, dest1, excludeExtensions); } } else { String extension = getExtension(src.getName()); if (!excludeExtensions.contains(extension)) { // This was not a directory, so lets just copy the file FileInputStream fin = null; FileOutputStream fout = null; byte[] buffer = new byte[4096]; // Buffer 4K at a time int bytesRead; try { // open the files for input and output fin = new FileInputStream(src); fout = new FileOutputStream(dest); // while bytesRead indicates a successful read, lets write... while ((bytesRead = fin.read(buffer)) >= 0) { fout.write(buffer, 0, bytesRead); } } catch (IOException e) { // Error copying file... IOException wrapper = new IOException("copyFiles: Unable to copy file: " + src.getAbsolutePath() + "to" + dest.getAbsolutePath() + "."); wrapper.initCause(e); wrapper.setStackTrace(e.getStackTrace()); throw wrapper; } finally { // Ensure that the files are closed (if they were open). if (fin != null) { fin.close(); } if (fout != null) { fout.close(); } } } else { System.out.println("Skipping " + src.getAbsolutePath()); } } }
From source file:de.ingrid.interfaces.csw.tools.FileUtils.java
/** * This function will copy files or directories from one location to * another. note that the source and the destination must be mutually * exclusive. This function can not be used to copy a directory to a sub * directory of itself. The function will also have problems if the * destination files already exist.//from www . j a v a 2 s. c o m * * @param src * -- A File object that represents the source for the copy * @param dest * -- A File object that represnts the destination for the copy. * @throws IOException * if unable to copy. * * Source: http://www.dreamincode.net/code/snippet1443.htm */ public static void copyRecursive(File src, File dest) throws IOException { // Check to ensure that the source is valid... if (!src.exists()) { throw new IOException("copyFiles: Can not find source: " + src.getAbsolutePath() + "."); } else if (!src.canRead()) { // check to ensure we have rights to the // source... throw new IOException("copyFiles: No right to source: " + src.getAbsolutePath() + "."); } // is this a directory copy? if (src.isDirectory()) { if (!dest.exists()) { // does the destination already exist? // if not we need to make it exist if possible (note this is // mkdirs not mkdir) if (!dest.mkdirs()) { throw new IOException("copyFiles: Could not create direcotry: " + dest.getAbsolutePath() + "."); } } // get a listing of files... String list[] = src.list(); // copy all the files in the list. for (String element : list) { File dest1 = new File(dest, element); File src1 = new File(src, element); copyRecursive(src1, dest1); } } else { // This was not a directory, so lets just copy the file FileInputStream fin = null; FileOutputStream fout = null; byte[] buffer = new byte[4096]; // Buffer 4K at a time (you can // change this). int bytesRead; try { // open the files for input and output fin = new FileInputStream(src); fout = new FileOutputStream(dest); // while bytesRead indicates a successful read, lets write... while ((bytesRead = fin.read(buffer)) >= 0) { fout.write(buffer, 0, bytesRead); } fin.close(); fout.close(); fin = null; fout = null; } catch (IOException e) { // Error copying file... IOException wrapper = new IOException("copyFiles: Unable to copy file: " + src.getAbsolutePath() + "to" + dest.getAbsolutePath() + "."); wrapper.initCause(e); wrapper.setStackTrace(e.getStackTrace()); throw wrapper; } finally { // Ensure that the files are closed (if they were open). if (fin != null) { fin.close(); } if (fout != null) { fin.close(); } } } }
From source file:net.sf.firemox.stack.EventManager.java
/** * remove all events in the stack of this phase, read new system abilities, * turn structure and set the current phase. * <ul>//from w ww . j a va 2 s . c o m * Structure of InputStream : Data[size] * <li>number of phases type [1]</li> * <li>phases type i [...]</li> * <li>number of phases in one turn [1]</li> * <li>phase identifier i [1]</li> * <li>phase index (not identifier) for first turn [1]</li> * <li>number of state based ability of play [1]</li> * <li>state based ability i [...]</li> * <li>number of static modifier of game [1]</li> * <li>static modifier of game i [...]</li> * </ul> * * @param dbStream * the MDB file containing rules * @param settingFile * setting file attached to this MDB * @throws IOException */ public static void init(FileInputStream dbStream, String settingFile) throws IOException { nextCurrentPlayer = -1; nextPhaseIndex = -1; // remove all event listener MEventListener.reset(); // read the different phase types int nbPhases = dbStream.read(); PhaseType[] phaseTypes = new PhaseType[nbPhases]; while (nbPhases-- > 0) { PhaseType phaseType = new PhaseType(dbStream); phaseTypes[phaseType.id] = phaseType; } // read the turn structure int nbPhasesPerTurn = dbStream.read(); turnStructure = new PhaseType[nbPhasesPerTurn]; Log.debug("Turn Structure :"); for (int i = 0; i < nbPhasesPerTurn; i++) { turnStructure[i] = phaseTypes[dbStream.read()]; Log.debug("\t" + i + ":" + turnStructure[i].phaseName); } // first phase index int startIdPhase = dbStream.read(); Log.debug( "First phase of first turn is " + turnStructure[startIdPhase].phaseName + "(" + startIdPhase + ")"); // read phases GUI try { final InputStream in = MToolKit.getResourceAsStream(settingFile.replace(".mdb", ".pref")); MPhase.phases = new MPhase[2][turnStructure.length]; for (int i = 0; i < turnStructure.length; i++) { MPhase.phases[0][i] = new MPhase(turnStructure[i], 0, in); } for (int i = 0; i < EventManager.turnStructure.length; i++) { MPhase.phases[1][i] = new MPhase(turnStructure[i], 1, in); } IOUtils.closeQuietly(in); } catch (IOException e) { JOptionPane.showMessageDialog(MagicUIComponents.magicForm, LanguageManager.getString("loadtbssettingspb") + " : " + e.getMessage() + e.getStackTrace()[0], LanguageManager.getString("error"), JOptionPane.WARNING_MESSAGE); } // read triggered abilities of play int nbTriggered = dbStream.read(); Log.debug("System abilities (" + nbTriggered + "):"); while (nbTriggered-- > 0) { // read the ability and register it AbilityFactory.readAbility(dbStream, SystemCard.instance).registerToManager(); } // reset the breakpoints, options and initialize all phases graphics for (int i = MPhase.phases[0].length; i-- > 1;) { MPhase.phases[0][i].reset(); MPhase.phases[1][i].reset(); } // set the current phase to ID__PHASE_MAIN phaseIndex = startIdPhase - 1; currentIdPhase = turnStructure[phaseIndex].id; parsingBeforePhaseEvent = false; parsingEndPhaseEvent = false; replacingBefore = false; // read static-modifiers of game int nbStaticModifiers = dbStream.read(); Log.debug("Static-modifiers (" + nbStaticModifiers + "):"); while (nbStaticModifiers-- > 0) { // read the static-modifiers and register them ModifierFactory.readModifier(dbStream).addModifierFromModel(SystemAbility.instance, SystemCard.instance); } }
From source file:internal.static_util.scorer.TermRelatednessScorer.java
/** * Gets the number of documents word appears in the document index. * * @param words The word(s) to do a documentSearch for. * @return The number of documents containing (all of) #words# *///ww w. j a v a2s . c om private static int getNumOfDocuments(String... words) { // Handle idiot cases if (words == null || words.length == 0) { return 0; } Query q = QueryUtils.mustContainWords(words); // Get the search call Callable<Integer> search = () -> { try { return searcher.count(q); } catch (IOException e) { log.error(TermRelatednessScorer.class.toString() + ": ERROR: Could not get term count for query " + q.toString() + "."); return 0; // Assume no documents then. } }; // Get the number of documents from the cache. int numDocuments = 0; try { numDocuments = cache.get(q.toString(), search); } catch (ExecutionException e) { log.error("[TermRelatednessScorer] ERROR: There was an error while populating the cache: " + e.getLocalizedMessage()); log.debug(e.getStackTrace()); } return numDocuments; }
From source file:org.apache.hadoop.hdfs.server.datanode.BlockSender.java
/** * Converts an IOExcpetion (not subclasses) to SocketException. * This is typically done to indicate to upper layers that the error * was a socket error rather than often more serious exceptions like * disk errors./*from w w w.j a v a 2s . co m*/ */ private static IOException ioeToSocketException(IOException ioe) { if (ioe.getClass().equals(IOException.class)) { // "se" could be a new class in stead of SocketException. IOException se = new SocketException("Original Exception : " + ioe); se.initCause(ioe); /* Change the stacktrace so that original trace is not truncated * when printed.*/ se.setStackTrace(ioe.getStackTrace()); return se; } // otherwise just return the same exception. return ioe; }
From source file:gov.nasa.ensemble.common.io.FileUtilities.java
/** * This function will copy files or directories from one location to another. note that the source and the destination must be mutually exclusive. This function can not be used to copy a directory * to a sub directory of itself. The function will also have problems if the destination files already exist. * // w ww . jav a 2 s . c om * @param src * -- A File object that represents the source for the copy * @param dest * -- A File object that represnts the destination for the copy. * @throws IOException * if unable to copy. */ public static void copyFiles(File src, File dest) throws IOException { // Check to ensure that the source is valid... if (!src.exists()) { throw new IOException("copyFiles: Can not find source: " + src.getAbsolutePath() + "."); } else if (!src.canRead()) { // check to ensure we have rights to the source... throw new IOException("copyFiles: No right to source: " + src.getAbsolutePath() + "."); } // is this a directory copy? if (src.isDirectory()) { if (!dest.exists()) { // does the destination already exist? // if not we need to make it exist if possible (note this is mkdirs not mkdir) if (!dest.mkdirs()) { throw new IOException("copyFiles: Could not create direcotry: " + dest.getAbsolutePath() + "."); } } // get a listing of files... String list[] = src.list(); // copy all the files in the list. for (int i = 0; i < list.length; i++) { File dest1 = new File(dest, list[i]); File src1 = new File(src, list[i]); copyFiles(src1, dest1); } } else { // This was not a directory, so lets just copy the file FileInputStream fin = null; FileOutputStream fout = null; byte[] buffer = new byte[4096]; // Buffer 4K at a time (you can change this). int bytesRead; try { // open the files for input and output fin = new FileInputStream(src); fout = new FileOutputStream(dest); // while bytesRead indicates a successful read, lets write... while ((bytesRead = fin.read(buffer)) >= 0) { fout.write(buffer, 0, bytesRead); } } catch (IOException e) { // Error copying file... IOException wrapper = new IOException("copyFiles: Unable to copy file: " + src.getAbsolutePath() + "to" + dest.getAbsolutePath() + "."); wrapper.initCause(e); wrapper.setStackTrace(e.getStackTrace()); throw wrapper; } finally { // Ensure that the files are closed (if they were open). if (fin != null) { fin.close(); } if (fout != null) { fout.close(); } } } }
From source file:com.dmitrymalkovich.android.githubanalytics.Utils.java
public static void openFeedback(Activity activity) { try {// w w w . ja v a 2s .c om throw new IOException(); } catch (IOException e) { ApplicationErrorReport report = new ApplicationErrorReport(); report.packageName = report.processName = activity.getApplication().getPackageName(); report.time = System.currentTimeMillis(); report.type = ApplicationErrorReport.TYPE_CRASH; report.systemApp = false; ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo(); crash.exceptionClassName = e.getClass().getSimpleName(); crash.exceptionMessage = e.getMessage(); StringWriter writer = new StringWriter(); PrintWriter printer = new PrintWriter(writer); e.printStackTrace(printer); crash.stackTrace = writer.toString(); StackTraceElement stack = e.getStackTrace()[0]; crash.throwClassName = stack.getClassName(); crash.throwFileName = stack.getFileName(); crash.throwLineNumber = stack.getLineNumber(); crash.throwMethodName = stack.getMethodName(); report.crashInfo = crash; Intent intent = new Intent(Intent.ACTION_APP_ERROR); intent.putExtra(Intent.EXTRA_BUG_REPORT, report); activity.startActivity(intent); } }