Example usage for java.io IOException IOException

List of usage examples for java.io IOException IOException

Introduction

In this page you can find the example usage for java.io IOException IOException.

Prototype

public IOException(Throwable cause) 

Source Link

Document

Constructs an IOException with the specified cause and a detail message of (cause==null ?

Usage

From source file:cfa.vo.interop.EncodeDoubleArray.java

private static byte[] doubleToByte(double[] data) throws IOException {

    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    DataOutputStream outputStream = new DataOutputStream(byteStream);

    try {//w  w  w.j  a v a 2s .  c  o m

        for (int ii = 0; ii < data.length; ii++)
            outputStream.writeDouble(data[ii]);

    } catch (EOFException e) {
        throw new IOException("Unable to read from dataInputStream, found EOF");

    } catch (IOException e) {
        throw new IOException("Unable to read from dataInputStream, IO error");
    }

    byte[] result = byteStream.toByteArray();

    return result;
}

From source file:org.thoughtcrime.securesms.mms.MmsSendHelper.java

private static byte[] makePost(MmsConnectionParameters parameters, byte[] mms)
        throws ClientProtocolException, IOException {
    Log.w("MmsSender", "Sending MMS1 of length: " + mms.length);
    try {// w w  w .ja  va  2  s  .  c  om
        HttpClient client = constructHttpClient(parameters);
        URI hostUrl = new URI(parameters.getMmsc());
        HttpHost target = new HttpHost(hostUrl.getHost(), hostUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME);
        HttpPost request = new HttpPost(parameters.getMmsc());
        ByteArrayEntity entity = new ByteArrayEntity(mms);

        entity.setContentType("application/vnd.wap.mms-message");

        request.setEntity(entity);
        request.setParams(client.getParams());
        request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");

        HttpResponse response = client.execute(target, request);
        StatusLine status = response.getStatusLine();

        if (status.getStatusCode() != 200)
            throw new IOException("Non-successful HTTP response: " + status.getReasonPhrase());

        return parseResponse(response.getEntity());
    } catch (URISyntaxException use) {
        Log.w("MmsDownlader", use);
        throw new IOException("Bad URI syntax");
    }
}

From source file:eu.europeana.enrichment.common.Utils.java

public static List<File> expandFileTemplateFrom(File dir, String... pattern) throws IOException {
    List<File> files = new ArrayList<File>();

    for (String p : pattern) {

        File fdir = new File(new File(dir, FilenameUtils.getFullPathNoEndSeparator(p)).getCanonicalPath());
        if (!fdir.isDirectory())
            throw new IOException("Error: " + fdir.getCanonicalPath() + ", expanded from directory "
                    + dir.getCanonicalPath() + " and pattern " + p + " does not denote a directory");
        if (!fdir.canRead())
            throw new IOException("Error: " + fdir.getCanonicalPath() + " is not readable");
        FileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getName(p));
        File[] list = fdir.listFiles(fileFilter);
        if (list == null)
            throw new IOException("Error: " + fdir.getCanonicalPath()
                    + " does not denote a directory or something else is wrong");
        if (list.length == 0)
            throw new IOException("Error: no files found, template " + p + " from dir " + dir.getCanonicalPath()
                    + " where we recognised " + fdir.getCanonicalPath() + " as path and " + fileFilter
                    + " as file mask");
        for (File file : list) {
            if (!file.exists()) {
                throw new FileNotFoundException(
                        "File not found: " + file + " resolved to " + file.getCanonicalPath());
            }/* w ww  .  ja va2s. c om*/
        }
        files.addAll(Arrays.asList(list));
    }

    return files;
}

From source file:com.alibaba.jstorm.utils.SystemOperation.java

public static String exec(String cmd) throws IOException {
    LOG.debug("Shell cmd: " + cmd);
    Process process = new ProcessBuilder(new String[] { "/bin/bash", "-c", cmd }).start();
    try {//from   ww  w  .  j  a va  2  s.  co  m
        process.waitFor();
        String output = IOUtils.toString(process.getInputStream());
        String errorOutput = IOUtils.toString(process.getErrorStream());
        LOG.debug("Shell Output: " + output);
        if (errorOutput.length() != 0) {
            LOG.error("Shell Error Output: " + errorOutput);
            throw new IOException(errorOutput);
        }
        return output;
    } catch (InterruptedException ie) {
        throw new IOException(ie.toString());
    }

}

From source file:mobi.jenkinsci.ci.client.sso.AssemblaSsoHandler.java

@Override
public IOException getException(final HttpResponse response) {
    return new IOException("Assembla Login Failed");
}

From source file:com.ecyrd.jspwiki.util.Serializer.java

/**
 * Deserializes a Base64-encoded String into a HashMap. Both the keys and values
 * must implement {@link java.io.Serializable}.
 * @param rawString the String contents containing the map to be deserialized
 * @return the attributes, parsed into a Map
 * @throws IOException if the contents cannot be parsed for any reason
 *//* w  w  w .j a v  a 2  s .  c  o m*/
@SuppressWarnings("unchecked")
public static Map<String, ? extends Serializable> deserializeFromBase64(String rawString) throws IOException {
    // Decode from Base64-encoded String to byte array
    byte[] decodedBytes = Base64.decodeBase64(rawString.getBytes("UTF-8"));

    // Deserialize from the input stream to the Map
    InputStream bytesIn = new ByteArrayInputStream(decodedBytes);
    ObjectInputStream in = new ObjectInputStream(bytesIn);
    HashMap<String, Serializable> attributes;
    try {
        attributes = (HashMap<String, Serializable>) in.readObject();
    } catch (ClassNotFoundException e) {
        throw new IOException("Could not deserialiaze user profile attributes. Reason: " + e.getMessage());
    } finally {
        in.close();
    }
    return attributes;
}

From source file:com.rapleaf.hank.storage.LocalPartitionRemoteFileOps.java

public LocalPartitionRemoteFileOps(String remoteDomainRoot, int partitionNumber) throws IOException {
    this.partitionRoot = remoteDomainRoot + "/" + partitionNumber;
    if (!new File(partitionRoot).isAbsolute()) {
        throw new IOException("Cannot initialize " + this.getClass().getSimpleName()
                + " with a non absolute remote partition root: " + partitionRoot);
    }/*from   ww  w  .  j a  v a2 s  .  c o  m*/
}

From source file:de.dfki.asr.compass.web.util.ResourceLoader.java

public InputStream getResourceAsStream(String resourceName) throws IOException {
    InputStream resourceStream = context.getResourceAsStream("/" + resourceName);
    if (resourceStream == null) {
        throw new IOException("Cannot find resource: " + resourceName);
    }//from ww  w . ja v a2s.  com
    return resourceStream;
}