List of usage examples for java.io IOException getMessage
public String getMessage()
From source file:net.sourceforge.lept4j.util.LoadLibs.java
/** * Copies resources from the jar file of the current thread and extract it * to the destination directory./*w w w . j a v a 2 s . c o m*/ * * @param jarConnection * @param destDir */ static void copyJarResourceToDirectory(JarURLConnection jarConnection, File destDir) { try { JarFile jarFile = jarConnection.getJarFile(); String jarConnectionEntryName = jarConnection.getEntryName() + "/"; /** * Iterate all entries in the jar file. */ for (Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements();) { JarEntry jarEntry = e.nextElement(); String jarEntryName = jarEntry.getName(); /** * Extract files only if they match the path. */ if (jarEntryName.startsWith(jarConnectionEntryName)) { String filename = jarEntryName.substring(jarConnectionEntryName.length()); File currentFile = new File(destDir, filename); if (jarEntry.isDirectory()) { currentFile.mkdirs(); } else { currentFile.deleteOnExit(); InputStream is = jarFile.getInputStream(jarEntry); OutputStream out = FileUtils.openOutputStream(currentFile); IOUtils.copy(is, out); is.close(); out.close(); } } } } catch (IOException e) { logger.log(Level.WARNING, e.getMessage(), e); } }
From source file:Main.java
public static ResponseHandler<String> GetResponseHandlerInstance(final Handler handler) { final ResponseHandler<String> responseHandler = new ResponseHandler<String>() { @Override// w ww.j a va 2 s.com public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException { Message message = handler.obtainMessage(); Bundle bundle = new Bundle(); StatusLine status = response.getStatusLine(); HttpEntity entity = response.getEntity(); String result = null; if (entity != null) { try { result = InputStreamToString(entity.getContent()); bundle.putString("RESPONSE", result); message.setData(bundle); handler.sendMessage(message); } catch (IOException e) { bundle.putString("RESPONSE", "Error - " + e.getMessage()); message.setData(bundle); handler.sendMessage(message); } } else { bundle.putString("RESPONSE", "Error - " + response.getStatusLine().getReasonPhrase()); message.setData(bundle); handler.sendMessage(message); } return result; } }; return responseHandler; }
From source file:org.artags.android.app.stackwidget.util.HttpUtils.java
private static String convertStreamToString(InputStream is) { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line;//from w w w. j a va 2s . c om try { while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } } catch (IOException e) { Log.e(HttpUtils.class.getName(), e.getMessage()); } finally { try { is.close(); } catch (IOException e) { Log.e(HttpUtils.class.getName(), e.getMessage()); } } return sb.toString(); }
From source file:com.magnet.plugin.common.helpers.URLHelper.java
public static boolean checkURL(String urlS) { FormattedLogger logger = new FormattedLogger(URLHelper.class); logger.append("checkURL:" + urlS); try {/*w ww .j av a2 s . com*/ URL url = new URL(urlS); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); logger.append("Response code: " + conn.getResponseCode()); logger.showInfoLog(); return true; } catch (IOException e) { logger.append(e.getMessage()); logger.showErrorLog(); } return false; }
From source file:com.microsoft.alm.client.utils.JsonHelper.java
@SuppressWarnings("unchecked") public static <T> T deserializeResponce(final HttpMethodBase response, final Class<T> clazz) { try {/*w ww . j av a 2 s . c o m*/ if (!InputStream.class.isAssignableFrom(clazz)) { final byte[] input = response.getResponseBody(); if (input == null || input.length == 0) { return null; } return objectMapper.readValue(input, clazz); } else if (response.getResponseContentLength() == 0) { return null; } else { final InputStream responseStream = response.getResponseBodyAsStream(); final Header contentTypeHeader = response.getResponseHeader(VssHttpHeaders.CONTENT_TYPE); if (contentTypeHeader != null && contentTypeHeader.getValue().equalsIgnoreCase(DownloadContentTypes.APPLICATION_GZIP)) { return (T) new GZIPInputStream(responseStream); } else { return (T) responseStream; } } } catch (final IOException e) { log.error(e.getMessage(), e); throw new VssServiceException(e.getMessage(), e); } finally { response.releaseConnection(); } }
From source file:ch.devmine.javaparser.Main.java
private static void parseAsDirectory(Project project, HashMap<String, Package> packs, List<Language> languages, Language language, String arg) { File repoRoot = new File(arg); Path repoPath = repoRoot.toPath(); FilesWalker fileWalker = new FilesWalker(); try {/*from w ww. ja v a2 s. c o m*/ Files.walkFileTree(repoPath, fileWalker); } catch (IOException ex) { Log.e(TAG, ex.getMessage()); } String path = repoPath.toString(); String name = path.substring(path.lastIndexOf("/") + 1); project.setName(name); for (String dir : fileWalker.getDirectories()) { dir = dir.replaceAll("\n", ""); if (FileTypeFinder.search(dir, ".java")) { Package pack = new Package(); String packName = dir.substring(dir.lastIndexOf("/") + 1); pack.setName(packName); pack.setPath(dir); packs.put(packName, pack); } } List<String> javaFiles = FileWalkerUtils.extractJavaFiles(fileWalker.getRegularFiles()); for (String javaFile : javaFiles) { try { Parser parser = new Parser(javaFile, null); SourceFile sourceFile = new SourceFile(); String packName = FileWalkerUtils.extractFolderName(javaFile); parseAndFillSourceFile(parser, sourceFile, javaFile, language, packs, packName); } catch (FileNotFoundException ex) { Log.e(TAG, ex.getMessage()); } } }
From source file:com.sap.prd.mobile.ios.mios.EffectiveBuildSettings.java
private static Properties extractBuildSettings(final IXCodeContext context) throws XCodeException { List<String> buildActions = Collections.emptyList(); IOptions options = context.getOptions(); Map<String, String> managedOptions = new HashMap<String, String>(options.getManagedOptions()); managedOptions.put(Options.ManagedOption.SHOWBUILDSETTINGS.getOptionName(), null); XCodeContext showBuildSettingsContext = new XCodeContext(buildActions, context.getProjectRootDirectory(), context.getOut(),/*from ww w . j a va2 s . c o m*/ new Settings(context.getSettings().getUserSettings(), context.getSettings().getManagedSettings()), new Options(options.getUserOptions(), managedOptions)); final CommandLineBuilder cmdLineBuilder = new CommandLineBuilder(showBuildSettingsContext); PrintStream out = null; ByteArrayOutputStream os = null; try { os = new ByteArrayOutputStream(); out = new PrintStream(os, true, Charset.defaultCharset().name()); final int returnValue = Forker.forkProcess(out, context.getProjectRootDirectory(), cmdLineBuilder.createBuildCall()); if (returnValue != 0) { if (out != null) out.flush(); throw new XCodeException( "Could not execute xcodebuild -showBuildSettings command for configuration " + context.getConfiguration() + " and sdk " + context.getSDK() + ": " + new String(os.toByteArray(), Charset.defaultCharset().name())); } out.flush(); Properties prop = new Properties(); prop.load(new ByteArrayInputStream(os.toByteArray())); return prop; } catch (IOException ex) { throw new XCodeException("Cannot extract build properties: " + ex.getMessage(), ex); } finally { IOUtils.closeQuietly(out); } }
From source file:org.artags.android.app.stackwidget.util.HttpUtils.java
public static String getUrl(String url) { String result = ""; HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url); HttpResponse response;/* w ww . ja v a 2s .c o m*/ try { response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); result = convertStreamToString(instream); } } catch (IOException ex) { Log.e(HttpUtils.class.getName(), ex.getMessage()); } return result; }
From source file:com.gmt2001.HttpRequest.java
public static HttpResponse getData(RequestType type, String url, String post, HashMap<String, String> headers) { Thread.setDefaultUncaughtExceptionHandler(com.gmt2001.UncaughtExceptionHandler.instance()); HttpResponse r = new HttpResponse(); r.type = type;//from w w w. ja v a 2s. c om r.url = url; r.post = post; r.headers = headers; try { URL u = new URL(url); HttpURLConnection h = (HttpURLConnection) u.openConnection(); for (Entry<String, String> e : headers.entrySet()) { h.addRequestProperty(e.getKey(), e.getValue()); } h.setRequestMethod(type.name()); h.setUseCaches(false); h.setDefaultUseCaches(false); h.setConnectTimeout(timeout); h.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.52 Safari/537.36 PhantomBotJ/2015"); if (!post.isEmpty()) { h.setDoOutput(true); } h.connect(); if (!post.isEmpty()) { BufferedOutputStream stream = new BufferedOutputStream(h.getOutputStream()); stream.write(post.getBytes()); stream.flush(); stream.close(); } if (h.getResponseCode() < 400) { r.content = IOUtils.toString(new BufferedInputStream(h.getInputStream()), h.getContentEncoding()); r.httpCode = h.getResponseCode(); r.success = true; } else { r.content = IOUtils.toString(new BufferedInputStream(h.getErrorStream()), h.getContentEncoding()); r.httpCode = h.getResponseCode(); r.success = false; } } catch (IOException ex) { r.success = false; r.httpCode = 0; r.exception = ex.getMessage(); com.gmt2001.Console.err.printStackTrace(ex); } return r; }
From source file:com.canoo.webtest.util.FileUtil.java
/** * Helper method for reading objects from a file. * * @param file the file to read from//from w ww . j a v a 2 s. c o m * @param step step requesting the operation * @return the object from the file if everything worked correctly */ public static Object tryReadObjectFromFile(final File file, final Step step) { FileInputStream fis = null; ObjectInputStream ois = null; String message = "finding"; try { fis = new FileInputStream(file); ois = new ObjectInputStream(fis); message = "reading from"; return StreamBoundary.tryReadObject(ois, step); } catch (IOException e) { LOG.error(e.getMessage(), e); throw new StepExecutionException("Error " + message + " file: " + e.getMessage(), step); } finally { IOUtils.closeQuietly(ois); IOUtils.closeQuietly(fis); } }