List of usage examples for java.io IOException initCause
public synchronized Throwable initCause(Throwable cause)
From source file:org.mule.modules.handshake.client.impl.AbstractHandshakeClient.java
/** * Parse JSON to specified type// ww w .java 2 s.c o m * * @param <V> type of the object to obtain * @param string JSON-formatted string to parse * @param type of the object to obtain * @return parsed object * @throws IOException if the string is not JSON-formatted */ protected <V> V parseJson(final String string, final Type type) throws IOException { try { return gson.fromJson(string, type); } catch (final JsonParseException jpe) { final IOException ioe = new IOException("Parse exception converting JSON to object"); //$NON-NLS-1$ ioe.initCause(jpe); throw ioe; } }
From source file:org.codehaus.mojo.mrm.impl.maven.FileSystemArtifactStore.java
/** * {@inheritDoc}/*from w ww.j a v a2 s.c o m*/ */ public Metadata getMetadata(String path) throws IOException, MetadataNotFoundException { Entry entry = backing.get(StringUtils.join(StringUtils.split(StringUtils.strip(path, "/"), "/"), "/") + "/maven-metadata.xml"); if (!(entry instanceof FileEntry)) { throw new MetadataNotFoundException(path); } MetadataXpp3Reader reader = new MetadataXpp3Reader(); InputStream inputStream = null; try { inputStream = ((FileEntry) entry).getInputStream(); return reader.read(inputStream); } catch (XmlPullParserException e) { IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; } finally { IOUtils.closeQuietly(inputStream); } }
From source file:net.sourceforge.stripes.controller.multipart.CommonsMultipartWrapper.java
/** * Pseudo-constructor that allows the class to perform any initialization necessary. * * @param request an HttpServletRequest that has a content-type of multipart. * @param tempDir a File representing the temporary directory that can be used to store * file parts as they are uploaded if this is desirable * @param maxPostSize the size in bytes beyond which the request should not be read, and a * FileUploadLimitExceeded exception should be thrown * @throws IOException if a problem occurs processing the request of storing temporary * files//ww w.ja v a2s .c o m * @throws FileUploadLimitExceededException if the POST content is longer than the * maxPostSize supplied. */ @SuppressWarnings("unchecked") public void build(HttpServletRequest request, File tempDir, long maxPostSize) throws IOException, FileUploadLimitExceededException { try { this.charset = request.getCharacterEncoding(); DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setRepository(tempDir); ServletFileUpload upload = new ServletFileUpload(factory); upload.setSizeMax(maxPostSize); List<FileItem> items = upload.parseRequest(request); Map<String, List<String>> params = new HashMap<String, List<String>>(); for (FileItem item : items) { // If it's a form field, add the string value to the list if (item.isFormField()) { List<String> values = params.get(item.getFieldName()); if (values == null) { values = new ArrayList<String>(); params.put(item.getFieldName(), values); } values.add(charset == null ? item.getString() : item.getString(charset)); } // Else store the file param else { files.put(item.getFieldName(), item); } } // Now convert them down into the usual map of String->String[] for (Map.Entry<String, List<String>> entry : params.entrySet()) { List<String> values = entry.getValue(); this.parameters.put(entry.getKey(), values.toArray(new String[values.size()])); } } catch (FileUploadBase.SizeLimitExceededException slee) { throw new FileUploadLimitExceededException(maxPostSize, slee.getActualSize()); } catch (FileUploadException fue) { IOException ioe = new IOException("Could not parse and cache file upload data."); ioe.initCause(fue); throw ioe; } }
From source file:com.eviware.soapui.impl.wsdl.submit.transports.http.HttpMethodSupport.java
public byte[] getDecompressedResponseBody() throws IOException { String compressionAlg = HttpClientSupport.getResponseCompressionType(httpMethod); if (compressionAlg != null) { try {// w ww . j av a 2 s . c om return CompressionSupport.decompress(compressionAlg, responseBody); } catch (Exception e) { IOException ioe = new IOException("Decompression of response failed"); ioe.initCause(e); throw ioe; } } return responseBody; }
From source file:org.geotools.gce.imagemosaic.Utils.java
/** * //from ww w .j av a 2 s. c o m * @param datastoreProperties * @return * @throws IOException */ public static Map<String, Serializable> createDataStoreParamsFromPropertiesFile(final URL datastoreProperties) throws IOException { // read the properties file Properties properties = loadPropertiesFromURL(datastoreProperties); if (properties == null) return null; // SPI final String SPIClass = properties.getProperty("SPI"); try { // create a datastore as instructed final DataStoreFactorySpi spi = (DataStoreFactorySpi) Class.forName(SPIClass).newInstance(); return createDataStoreParamsFromPropertiesFile(properties, spi); } catch (ClassNotFoundException e) { final IOException ioe = new IOException(); throw (IOException) ioe.initCause(e); } catch (InstantiationException e) { final IOException ioe = new IOException(); throw (IOException) ioe.initCause(e); } catch (IllegalAccessException e) { final IOException ioe = new IOException(); throw (IOException) ioe.initCause(e); } }
From source file:org.ardverk.daap.bio.DaapConnectionBIO.java
private DaapRequest readRequest() throws IOException { String line = null;//from w w w. j av a2s . c o m do { line = HttpParser.readLine(in); } while (line != null && line.length() == 0); if (line == null) { throw new IOException("Request is null: " + this); } DaapRequest request = null; try { request = new DaapRequest(this, line); Header[] headers = HttpParser.parseHeaders(in); request.addHeaders(headers); return request; } catch (URISyntaxException e) { IOException ioe = new IOException(); ioe.initCause(e); throw ioe; } catch (HttpException e) { IOException ioe = new IOException(); ioe.initCause(e); throw ioe; } }
From source file:org.paxle.core.doc.impl.BasicDocumentFactory.java
public <Doc> Doc unmarshal(InputStream input, Map<String, DataHandler> attachments) throws IOException { try {/*from w ww.j a v a 2 s . com*/ final Unmarshaller u = context.createUnmarshaller(); u.setAdapter(JaxbFileAdapter.class, new JaxbFileAdapter(this.tempFileManager, attachments)); u.setAdapter(JaxbFieldMapAdapter.class, new JaxbFieldMapAdapter(this.tempFileManager)); u.setAttachmentUnmarshaller(new JaxbAttachmentUnmarshaller(attachments)); // u.setProperty("com.sun.xml.bind.ObjectFactory", new BasicJaxbFactory()); @SuppressWarnings("unchecked") final Doc document = (Doc) u.unmarshal(input); return document; } catch (JAXBException e) { final IOException ioe = new IOException( String.format("Unable to unmarshal the document from the stream.")); ioe.initCause(e); throw ioe; } }
From source file:net.sourceforge.stripes.controller.multipart.CommonsMultipartWrapper.java
/** * Responsible for constructing a FileBean object for the named file parameter. If there is no * file parameter with the specified name this method should return null. * * @param name the name of the file parameter * @return a FileBean object wrapping the uploaded file *///from w w w . j av a2 s . c om public FileBean getFileParameterValue(String name) { final FileItem item = this.files.get(name); if (item == null || ((item.getName() == null || item.getName().length() == 0) && item.getSize() == 0)) { return null; } else { // Attempt to ensure the file name is just the basename with no path included String filename = item.getName(); int index; if (WINDOWS_PATH_PREFIX_PATTERN.matcher(filename).find()) index = filename.lastIndexOf('\\'); else index = filename.lastIndexOf('/'); if (index >= 0 && index + 1 < filename.length() - 1) filename = filename.substring(index + 1); // Use an anonymous inner subclass of FileBean that overrides all the // methods that rely on having a File present, to use the FileItem // created by commons upload instead. return new FileBean(null, item.getContentType(), filename, this.charset) { @Override public long getSize() { return item.getSize(); } @Override public InputStream getInputStream() throws IOException { return item.getInputStream(); } @Override public void save(File toFile) throws IOException { try { item.write(toFile); delete(); } catch (Exception e) { if (e instanceof IOException) throw (IOException) e; else { IOException ioe = new IOException("Problem saving uploaded file."); ioe.initCause(e); throw ioe; } } } @Override public void delete() throws IOException { item.delete(); } }; } }
From source file:com.manydesigns.portofino.stripes.StreamingCommonsMultipartWrapper.java
/** * Pseudo-constructor that allows the class to perform any initialization necessary. * * @param request an HttpServletRequest that has a content-type of multipart. * @param tempDir a File representing the temporary directory that can be used to store * file parts as they are uploaded if this is desirable * @param maxPostSize the size in bytes beyond which the request should not be read, and a * FileUploadLimitExceeded exception should be thrown * @throws IOException if a problem occurs processing the request of storing temporary * files// w ww. j av a 2 s. c om * @throws FileUploadLimitExceededException if the POST content is longer than the * maxPostSize supplied. */ @SuppressWarnings("unchecked") public void build(HttpServletRequest request, File tempDir, long maxPostSize) throws IOException, FileUploadLimitExceededException { try { this.charset = request.getCharacterEncoding(); DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setRepository(tempDir); ServletFileUpload upload = new ServletFileUpload(factory); upload.setSizeMax(maxPostSize); FileItemIterator iterator = upload.getItemIterator(request); Map<String, List<String>> params = new HashMap<String, List<String>>(); while (iterator.hasNext()) { FileItemStream item = iterator.next(); InputStream stream = item.openStream(); // If it's a form field, add the string value to the list if (item.isFormField()) { List<String> values = params.get(item.getFieldName()); if (values == null) { values = new ArrayList<String>(); params.put(item.getFieldName(), values); } values.add(charset == null ? IOUtils.toString(stream) : IOUtils.toString(stream, charset)); } // Else store the file param else { TempFile tempFile = TempFileService.getInstance().newTempFile(item.getContentType(), item.getName()); int size = IOUtils.copy(stream, tempFile.getOutputStream()); FileItem fileItem = new FileItem(item.getName(), item.getContentType(), tempFile, size); files.put(item.getFieldName(), fileItem); } } // Now convert them down into the usual map of String->String[] for (Map.Entry<String, List<String>> entry : params.entrySet()) { List<String> values = entry.getValue(); this.parameters.put(entry.getKey(), values.toArray(new String[values.size()])); } } catch (FileUploadBase.SizeLimitExceededException slee) { throw new FileUploadLimitExceededException(maxPostSize, slee.getActualSize()); } catch (FileUploadException fue) { IOException ioe = new IOException("Could not parse and cache file upload data."); ioe.initCause(fue); throw ioe; } }
From source file:org.codehaus.mojo.mrm.impl.maven.DiskArtifactStore.java
/** * {@inheritDoc}//from w w w .ja v a 2 s .c o m */ public Metadata getMetadata(String path) throws IOException, MetadataNotFoundException { File file = root; String[] parts = StringUtils.strip(path, "/").split("/"); for (int i = 0; i < parts.length; i++) { file = new File(file, parts[i]); } file = new File(file, "maven-metadata.xml"); if (!file.isFile()) { throw new MetadataNotFoundException(path); } MetadataXpp3Reader reader = new MetadataXpp3Reader(); InputStream inputStream = null; try { inputStream = new FileInputStream(file); return reader.read(inputStream); } catch (XmlPullParserException e) { IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; } finally { IOUtils.closeQuietly(inputStream); } }