List of usage examples for java.io IOException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.epam.reportportal.apache.http.impl.execchain.RetryExec.java
public CloseableHttpResponse execute(final HttpRoute route, final HttpRequestWrapper request, final HttpClientContext context, final HttpExecutionAware execAware) throws IOException, HttpException { Args.notNull(route, "HTTP route"); Args.notNull(request, "HTTP request"); Args.notNull(context, "HTTP context"); final Header[] origheaders = request.getAllHeaders(); for (int execCount = 1;; execCount++) { try {/*from w ww . j a v a 2s . c o m*/ return this.requestExecutor.execute(route, request, context, execAware); } catch (final IOException ex) { if (execAware != null && execAware.isAborted()) { this.log.debug("Request has been aborted"); throw ex; } if (retryHandler.retryRequest(ex, execCount, context)) { if (this.log.isInfoEnabled()) { this.log.info("I/O exception (" + ex.getClass().getName() + ") caught when processing request: " + ex.getMessage()); } if (this.log.isDebugEnabled()) { this.log.debug(ex.getMessage(), ex); } if (!Proxies.isRepeatable(request)) { this.log.debug("Cannot retry non-repeatable request"); throw new NonRepeatableRequestException( "Cannot retry request " + "with a non-repeatable request entity", ex); } request.setHeaders(origheaders); this.log.info("Retrying request"); } else { throw ex; } } } }
From source file:de.tudarmstadt.lt.ltbot.writer.SentenceWriter.java
@Override protected void innerProcess(CrawlURI curi) throws InterruptedException { try {/*w ww . j ava 2 s. c om*/ File basedir = getPath().getFile(); FileUtils.ensureWriteableDirectory(basedir); } catch (IOException e) { throw new RuntimeException(String.format("Could not ensure writeable base directory '%s'. %s: %s.", getPath(), e.getClass().getName(), e.getMessage()), e); } _num_uris.getAndIncrement(); RecordingInputStream recis = curi.getRecorder().getRecordedInput(); if (0L == recis.getResponseContentLength()) { return; } // content already written for this URI. boolean is_revisited = curi.getData().containsKey(SENTENCE_EXTRACT); if (is_revisited) return; try { String cleaned_plaintext = _textExtractorInstance.getCleanedUtf8PlainText(curi); updateOuputFile(); writeSentences(curi, cleaned_plaintext); String cleaned_plaintext_abbr = StringUtils.abbreviate(cleaned_plaintext, 50); curi.getData().put(SENTENCE_EXTRACT, cleaned_plaintext_abbr); } catch (IOException e) { curi.getNonFatalFailures().add(e); } }
From source file:org.tomahawk.libtomahawk.resolver.ScriptAccount.java
public ScriptAccount(String path, boolean manuallyInstalled) { String prefix = manuallyInstalled ? "file://" : "file:///android_asset"; mPath = prefix + path;/*from ww w . ja v a 2s .c o m*/ mManuallyInstalled = manuallyInstalled; String[] parts = mPath.split("/"); mName = parts[parts.length - 1]; try { InputStream inputStream; if (mManuallyInstalled) { File metadataFile = new File(path + File.separator + "content" + File.separator + "metadata.json"); inputStream = new FileInputStream(metadataFile); } else { inputStream = TomahawkApp.getContext().getAssets() .open(path.substring(1) + "/content/metadata.json"); } String metadataString = IOUtils.toString(inputStream, Charsets.UTF_8); mMetaData = GsonHelper.get().fromJson(metadataString, ScriptResolverMetaData.class); if (mMetaData == null) { Log.e(TAG, "Couldn't read metadata.json. Cannot instantiate ScriptAccount."); return; } } catch (IOException e) { Log.e(TAG, "ScriptAccount: " + e.getClass() + ": " + e.getLocalizedMessage()); Log.e(TAG, "Couldn't read metadata.json. Cannot instantiate ScriptAccount."); return; } mWebView = new WebView(TomahawkApp.getContext()); WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setDatabaseEnabled(true); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) { //noinspection deprecation settings.setDatabasePath(TomahawkApp.getContext().getDir("databases", Context.MODE_PRIVATE).getPath()); } settings.setDomStorageEnabled(true); mWebView.setWebChromeClient(new TomahawkWebChromeClient()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { //initalize WebView String data = "<!DOCTYPE html>" + "<html>" + "<head><title>" + mName + "</title></head>" + "<body>" + "<script src=\"file:///android_asset/js/rsvp-latest.min.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/cryptojs-core.js" + "\" type=\"text/javascript\"></script>"; if (mMetaData.manifest.scripts != null) { for (String scriptPath : mMetaData.manifest.scripts) { data += "<script src=\"" + mPath + "/content/" + scriptPath + "\" type=\"text/javascript\"></script>"; } } try { String[] cryptoJsScripts = TomahawkApp.getContext().getAssets().list("js/cryptojs"); for (String scriptPath : cryptoJsScripts) { data += "<script src=\"file:///android_asset/js/cryptojs/" + scriptPath + "\" type=\"text/javascript\"></script>"; } } catch (IOException e) { Log.e(TAG, "ScriptResolver: " + e.getClass() + ": " + e.getLocalizedMessage()); } data += "<script src=\"file:///android_asset/js/tomahawk_android_pre.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/tomahawk.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/tomahawk-infosystem.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/tomahawk_android_post.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"" + mPath + "/content/" + mMetaData.manifest.main + "\" type=\"text/javascript\"></script>" + "</body></html>"; mWebView.setWebViewClient(new ScriptWebViewClient(ScriptAccount.this)); mWebView.addJavascriptInterface(new ScriptInterface(ScriptAccount.this), SCRIPT_INTERFACE_NAME); mWebView.loadDataWithBaseURL("file:///android_asset/test.html", data, "text/html", null, null); } }); }
From source file:com.moss.appsnap.keeper.windows.MSWindowsAppHandler.java
@Override public void launch() { InstallableId id = info.currentVersion(); if (id == null) { throw new NullPointerException("There is no current version for " + info.id()); }/*ww w . ja va 2s.com*/ ResolvedJavaLaunchSpec rls = guts.data.javaLaunchSpecs.get(id); StringBuilder line = launchCommand(rls); try { Process p; if (info.isKeeperSoftware()) { // System.out.println("Using line: " + line); // String regex = "\""; // String replacement = "\\\\\""; // String arg = line.toString().replaceAll(regex, replacement); // System.out.println("Using arg: " + arg); ProcessBuilder pb = new ProcessBuilder(daemonLauncherExe.getAbsolutePath()); pb.directory(installDirPath); p = pb.start(); } else { p = Runtime.getRuntime().exec(line.toString()); } new MonitorThread(p).start(); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, "Launch error: " + e.getClass().getSimpleName() + ": " + e.getMessage()); } // JOptionPane.showMessageDialog(null, "ERROR: NOT YET IMPLEMENTED"); }
From source file:org.efaps.webdav4vfs.test.ramvfs.RamFileSystem.java
/** * Import the given file with the name relative to the given root. * * @param _fo file object/* w w w. j a v a2s .c om*/ * @param _root root file object * @throws FileSystemException if file object could not be imported */ void toRamFileObject(final FileObject _fo, final FileObject _root) throws FileSystemException { final RamFileObject memFo = (RamFileObject) this .resolveFile(_fo.getName().getPath().substring(_root.getName().getPath().length())); if (_fo.getType().hasChildren()) { // Create Folder memFo.createFolder(); // Import recursively final FileObject[] fos = _fo.getChildren(); for (int i = 0; i < fos.length; i++) { final FileObject child = fos[i]; this.toRamFileObject(child, _root); } } else if (_fo.getType().equals(FileType.FILE)) { // Read bytes try { final InputStream is = _fo.getContent().getInputStream(); try { final OutputStream os = new BufferedOutputStream(memFo.getOutputStream(), 512); int i; while ((i = is.read()) != -1) { os.write(i); } os.flush(); os.close(); } finally { try { is.close(); } catch (final IOException e) { // ignore on close exception } } } catch (final IOException e) { throw new FileSystemException(e.getClass().getName() + " " + e.getMessage()); } } else { throw new FileSystemException("File is not a folder nor a file " + memFo); } }
From source file:com.cndatacom.ordersystem.manager.RetryHandler.java
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { boolean retry = true; Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (executionCount > maxRetries) { // Do not retry if over max retry count retry = false;/*from ww w. java 2 s .co m*/ } else if (exceptionBlacklist.contains(exception.getClass())) { // immediately cancel retry if the error is blacklisted retry = false; } else if (exceptionWhitelist.contains(exception.getClass())) { // immediately retry if error is whitelisted retry = true; } else if (!sent) { // for most other errors, retry only if request hasn't been fully sent yet retry = true; } if (retry) { // resend all idempotent requests HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); String requestType = currentReq.getMethod(); retry = !requestType.equals("POST"); } if (retry) { SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); } return retry; }
From source file:cn.salesuite.saf.http.RetryHandler.java
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { boolean retry; Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (executionCount > maxRetries) { // Do not retry if over max retry count retry = false;/*from w w w. j av a 2 s . c o m*/ } else if (exceptionBlacklist.contains(exception.getClass())) { // immediately cancel retry if the error is blacklisted retry = false; } else if (exceptionWhitelist.contains(exception.getClass())) { // immediately retry if error is whitelisted retry = true; } else if (!sent) { // for most other errors, retry only if request hasn't been fully sent yet retry = true; } else { // resend all idempotent requests HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); String requestType = currentReq.getMethod(); if (!requestType.equals("POST")) { retry = true; } else { // otherwise do not retry retry = false; } } if (retry) { SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); } return retry; }
From source file:com.blazeroni.reddit.http.RetryHandler.java
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { boolean retry; Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (executionCount > this.maxRetries) { // Do not retry if over max retry count retry = false;/*from w w w. ja v a2 s . c o m*/ } else if (EXCEPTION_MAP.containsKey(exception.getClass())) { // immediately cancel retry if the error is blacklisted // immediately retry if error is whitelisted return EXCEPTION_MAP.get(exception.getClass()); } else if (!sent) { // for most other errors, retry only if request hasn't been fully sent yet retry = true; } else { // resend all idempotent requests HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); String requestType = currentReq.getMethod(); if (!requestType.equals("POST")) { retry = true; } else { // otherwise do not retry retry = false; } } if (retry) { SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { Log.debug("Not retrying request", exception); } return retry; }
From source file:com.google.httputils.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { boolean retry; Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (executionCount > maxRetries) { // Do not retry if over max retry count retry = false;// w ww . j a va 2s. c o m } else if (exceptionBlacklist.contains(exception.getClass())) { // immediately cancel retry if the error is blacklisted retry = false; } else if (exceptionWhitelist.contains(exception.getClass())) { // immediately retry if error is whitelisted retry = true; } else if (!sent) { // for most other errors, retry only if request hasn't been fully sent yet retry = true; } else { // resend all idempotent requests HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); String requestType = currentReq.getMethod(); if (!requestType.equals("POST")) { retry = true; } else { // otherwise do not retry retry = false; } } if (retry) { SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); } return retry; }
From source file:com.example.wechatsample.library.http.RetryHandler.java
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { boolean retry = true; Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (executionCount > maxRetries) { // Do not retry if over max retry count retry = false;/*from w w w . j a v a 2 s . c o m*/ } else if (exceptionBlacklist.contains(exception.getClass())) { // immediately cancel retry if the error is blacklisted retry = false; } else if (exceptionWhitelist.contains(exception.getClass())) { // immediately retry if error is whitelisted retry = true; } else if (!sent) { // for most other errors, retry only if request hasn't been fully // sent yet retry = true; } if (retry) { // resend all idempotent requests HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); String requestType = currentReq.getMethod(); retry = !requestType.equals("POST"); } if (retry) { SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); } return retry; }