List of usage examples for java.io IOException getMessage
public String getMessage()
From source file:com.amalto.workbench.utils.MDMServerHelper.java
private static boolean saveRootElement(Element rootElement) { try {// www .jav a 2 s . c om XMLWriter writer = new XMLWriter(new FileWriter(MDMServerHelper.workbenchConfigFile)); writer.write(rootElement.getDocument()); writer.close(); return true; } catch (IOException e) { log.error(e.getMessage(), e); return false; } }
From source file:com.zxy.commons.mq.producer.ObjectProducer.java
/** * Producer message// www . j a v a 2 s . c o m * * <p> * kafka_producer.propertiesproducer.type? * * @param <T> value class * @param topic topic * @param routerKey key? * @param value value */ public static <T> void producer4Kryo(String topic, String routerKey, T value) { try { byte[] bytes = KryoSeriizationUtils.serializationObject(value); ObjectProducerBuilder.BUILDER.sendMessage(topic, routerKey, bytes); } catch (IOException e) { throw new DatasAccessException(e.getMessage(), e); } }
From source file:net.sf.ehcache.distribution.PayloadUtil.java
/** * The fastest Ungzip implementation. See PageInfoTest in ehcache-constructs. * A high performance implementation, although not as fast as gunzip3. * gunzips 100000 of ungzipped content in 9ms on the reference machine. * It does not use a fixed size buffer and is therefore suitable for arbitrary * length arrays.// w w w .j av a2s .c o m * * @param gzipped * @return a plain, uncompressed byte[] */ public static byte[] ungzip(final byte[] gzipped) { byte[] ungzipped = new byte[0]; try { final GZIPInputStream inputStream = new GZIPInputStream(new ByteArrayInputStream(gzipped)); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(gzipped.length); final byte[] buffer = new byte[PayloadUtil.MTU]; int bytesRead = 0; while (bytesRead != -1) { bytesRead = inputStream.read(buffer, 0, PayloadUtil.MTU); if (bytesRead != -1) { byteArrayOutputStream.write(buffer, 0, bytesRead); } } ungzipped = byteArrayOutputStream.toByteArray(); inputStream.close(); byteArrayOutputStream.close(); } catch (IOException e) { LOG.fatal("Could not ungzip. Heartbeat will not be working. " + e.getMessage()); } return ungzipped; }
From source file:Zip.java
/** * Reads a Zip file, iterating through each entry and dumping the contents * to the console./*from w ww. j a v a2 s. c o m*/ */ public static void readZipFile(String fileName) { ZipFile zipFile = null; try { // ZipFile offers an Enumeration of all the files in the Zip file zipFile = new ZipFile(fileName); for (Enumeration e = zipFile.entries(); e.hasMoreElements();) { ZipEntry zipEntry = (ZipEntry) e.nextElement(); System.out.println(zipEntry.getName() + " contains:"); // use BufferedReader to get one line at a time BufferedReader zipReader = new BufferedReader( new InputStreamReader(zipFile.getInputStream(zipEntry))); while (zipReader.ready()) { System.out.println(zipReader.readLine()); } zipReader.close(); } } catch (IOException ioe) { System.out.println("An IOException occurred: " + ioe.getMessage()); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException ioe) { } } } }
From source file:eionet.gdem.utils.HttpUtils.java
/** * Downloads remote file/*from w w w . ja v a 2 s .c o m*/ * @param url URL * @return Downloaded file * @throws DCMException If an error occurs. * @throws IOException If an error occurs. */ public static byte[] downloadRemoteFile(String url) throws DCMException, IOException { byte[] responseBody = null; CloseableHttpClient client = HttpClients.createDefault(); // Create a method instance. HttpGet method = new HttpGet(url); // Execute the method. CloseableHttpResponse response = null; try { response = client.execute(method); HttpEntity entity = response.getEntity(); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { LOGGER.error("Method failed: " + response.getStatusLine().getReasonPhrase()); throw new DCMException(BusinessConstants.EXCEPTION_SCHEMAOPEN_ERROR, response.getStatusLine().getReasonPhrase()); } // Read the response body. InputStream instream = entity.getContent(); responseBody = IOUtils.toByteArray(instream); // Deal with the response. // Use caution: ensure correct character encoding and is not binary data // System.out.println(new String(responseBody)); /*catch (HttpException e) { LOGGER.error("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); throw e;*/ } catch (IOException e) { LOGGER.error("Fatal transport error: " + e.getMessage()); e.printStackTrace(); throw e; } finally { // Release the connection. response.close(); method.releaseConnection(); client.close(); } return responseBody; }
From source file:apim.restful.importexport.utils.ArchiveGeneratorUtil.java
/** * Add files of the directory to the archive * * @param directoryToZip Location of the archive * @param file File to be included in the archive * @param zipOutputStream Output stream/*from ww w . jav a2 s . co m*/ * @throws APIExportException If an error occurs while writing files to the archive */ private static void addToArchive(File directoryToZip, File file, ZipOutputStream zipOutputStream) throws APIExportException { FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(file); // Get relative path from archive directory to the specific file String zipFilePath = file.getCanonicalPath().substring(directoryToZip.getCanonicalPath().length() + 1, file.getCanonicalPath().length()); if (File.separatorChar != '/') zipFilePath = zipFilePath.replace(File.separatorChar, APIImportExportConstants.ARCHIVE_PATH_SEPARATOR); ZipEntry zipEntry = new ZipEntry(zipFilePath); zipOutputStream.putNextEntry(zipEntry); IOUtils.copy(fileInputStream, zipOutputStream); zipOutputStream.closeEntry(); } catch (IOException e) { log.error("I/O error while writing files to archive" + e.getMessage()); throw new APIExportException("I/O error while writing files to archive", e); } finally { IOUtils.closeQuietly(fileInputStream); } }
From source file:com.igrow.mall.common.util.Struts2Utils.java
/** * ./*from ww w .j a va 2 s.c o m*/ * eg. * render("text/plain", "hello", "encoding:GBK"); * render("text/plain", "hello", "no-cache:false"); * render("text/plain", "hello", "encoding:GBK", "no-cache:false"); * * @param headers ??header??"encoding:""no-cache:",UTF-8true. */ public static void render(final String contentType, final String content, final String... headers) { try { //?headers? String encoding = ENCODING_DEFAULT; boolean noCache = NOCACHE_DEFAULT; for (String header : headers) { String headerName = StringUtils.substringBefore(header, ":"); String headerValue = StringUtils.substringAfter(header, ":"); if (StringUtils.equalsIgnoreCase(headerName, ENCODING_PREFIX)) { encoding = headerValue; } else if (StringUtils.equalsIgnoreCase(headerName, NOCACHE_PREFIX)) { noCache = Boolean.parseBoolean(headerValue); } else throw new IllegalArgumentException(headerName + "??header"); } HttpServletResponse response = ServletActionContext.getResponse(); //headers? String fullContentType = contentType + ";charset=" + encoding; response.setContentType(fullContentType); if (noCache) { response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); } response.getWriter().write(content); response.getWriter().flush(); } catch (IOException e) { logger.error(e.getMessage(), e); } }
From source file:com.sshtools.j2ssh.transport.publickey.SshKeyPairFactory.java
/** * * * @param encoded/*from ww w . j a va2 s . c o m*/ * * @return * * @throws InvalidSshKeyException * @throws AlgorithmNotSupportedException */ public static SshPrivateKey decodePrivateKey(byte[] encoded) throws InvalidSshKeyException, AlgorithmNotSupportedException { try { ByteArrayReader bar = new ByteArrayReader(encoded); String algorithm = bar.readString(); if (supportsKey(algorithm)) { SshKeyPair pair = newInstance(algorithm); return pair.decodePrivateKey(encoded); } else { throw new AlgorithmNotSupportedException(algorithm + " is not supported"); } } catch (IOException ioe) { throw new InvalidSshKeyException(ioe.getMessage()); } }
From source file:com.sshtools.j2ssh.transport.publickey.SshKeyPairFactory.java
/** * * * @param encoded//from ww w .j ava 2s. c o m * * @return * * @throws InvalidSshKeyException * @throws AlgorithmNotSupportedException */ public static SshPublicKey decodePublicKey(byte[] encoded) throws InvalidSshKeyException, AlgorithmNotSupportedException { try { ByteArrayReader bar = new ByteArrayReader(encoded); String algorithm = bar.readString(); if (supportsKey(algorithm)) { SshKeyPair pair = newInstance(algorithm); return pair.decodePublicKey(encoded); } else { throw new AlgorithmNotSupportedException(algorithm + " is not supported"); } } catch (IOException ioe) { throw new InvalidSshKeyException(ioe.getMessage()); } }
From source file:ch.devmine.javaparser.Main.java
private static void parseAsTarArchive(Project project, HashMap<String, Package> packs, List<Language> languages, Language language, String arg) { int slashIndex = arg.lastIndexOf("/"); String projectName = arg.substring(slashIndex + 1, arg.lastIndexOf(".")); String projectRoute = arg.substring(0, slashIndex + 1); project.setName(projectName);//from ww w . java 2 s . c o m try { TarArchiveInputStream tarInput = new TarArchiveInputStream(new FileInputStream(arg)); TarArchiveEntry entry; while (null != (entry = tarInput.getNextTarEntry())) { String entryName = entry.getName(); String fileName = entryName.substring(entryName.lastIndexOf("/") + 1); if (entryName.endsWith(".java") && !(fileName.startsWith("~") || fileName.startsWith("."))) { // add package containing source file to hashmap Package pack = new Package(); String packName = FileWalkerUtils.extractFolderName(entry.getName()); String packPath = extractPackagePath(entry.getName()); pack.setName(packName); pack.setPath(packPath); if (packs.get(packName) == null) { packs.put(packName, pack); } // parse java file String entryPath = projectRoute.concat(entryName); Parser parser = new Parser(entryPath, tarInput); SourceFile sourceFile = new SourceFile(); parseAndFillSourceFile(parser, sourceFile, entryPath, language, packs, packName); } } } catch (IOException ex) { Log.e(TAG, ex.getMessage()); } }