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:com.adguard.android.filtering.api.HttpServiceClient.java

/**
 * Downloads string from the specified url.
 *
 * @param downloadUrl Download url/*  w ww .j a v  a 2s. c  om*/
 * @return String or null
 * @throws IOException
 */
public static String downloadString(String downloadUrl) throws IOException {
    LOG.debug("Sending HTTP GET request to {}", downloadUrl);

    final String response = UrlUtils.downloadString(downloadUrl, READ_TIMEOUT, CONNECTION_TIMEOUT);
    if (StringUtils.isEmpty(response)) {
        LOG.error("Response for {} is empty", downloadUrl);
        throw new IOException("Response is empty.");
    }

    LOG.debug("Got response:{}", response);
    return response;
}

From source file:org.fdroid.enigtext.mms.MmsSendHelper.java

private static byte[] makePost(Context context, MmsConnectionParameters parameters, byte[] mms)
        throws ClientProtocolException, IOException {
    AndroidHttpClient client = null;/* ww  w  .  ja v  a  2  s  .c o  m*/

    try {
        Log.w("MmsSender", "Sending MMS1 of length: " + (mms != null ? mms.length : "null"));
        client = constructHttpClient(context, parameters);
        URI targetUrl = new URI(parameters.getMmsc());

        if (Util.isEmpty(targetUrl.getHost()))
            throw new IOException("Invalid target host: " + targetUrl.getHost() + " , " + targetUrl);

        HttpHost target = new HttpHost(targetUrl.getHost(), targetUrl.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");
        request.addHeader("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml");
        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("MmsSendHelper", use);
        throw new IOException("Couldn't parse URI.");
    } finally {
        if (client != null)
            client.close();
    }
}

From source file:com.github.droidfu.http.ssl.EasySSLSocketFactory.java

private static SSLContext createEasySSLContext() throws IOException {
    try {/*from ww w .j  av a  2s. co m*/
        SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, null, null);
        return context;
    } catch (Exception e) {
        throw new IOException(e.getMessage());
    }
}

From source file:com.blackducksoftware.integration.hub.detect.util.DetectZipUtil.java

public static void unzip(File zip, File dest, Charset charset) throws IOException {
    Path destPath = dest.toPath();
    try (ZipFile zipFile = new ZipFile(zip, ZipFile.OPEN_READ, charset)) {
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            Path entryPath = destPath.resolve(entry.getName());
            if (!entryPath.normalize().startsWith(dest.toPath()))
                throw new IOException("Zip entry contained path traversal");
            if (entry.isDirectory()) {
                Files.createDirectories(entryPath);
            } else {
                Files.createDirectories(entryPath.getParent());
                try (InputStream in = zipFile.getInputStream(entry)) {
                    try (OutputStream out = new FileOutputStream(entryPath.toFile())) {
                        IOUtils.copy(in, out);
                    }//from   www .  j  a  va 2 s . co  m
                }
            }
        }
    }
}

From source file:com.splicemachine.derby.stream.output.PipelineWriterBuilder.java

public static PipelineWriterBuilder getHTableWriterBuilderFromBase64String(String base64String)
        throws IOException {
    if (base64String == null)
        throw new IOException("tableScanner base64 String is null");
    return (PipelineWriterBuilder) SerializationUtils.deserialize(Base64.decodeBase64(base64String));
}

From source file:Main.java

public static byte[] getFileAsBytes(File file) {
    byte[] bytes = null;
    InputStream is = null;//from   w  w  w  . j a va 2  s.  c  om
    try {
        is = new FileInputStream(file);

        // Get the size of the file
        long length = file.length();
        if (length > Integer.MAX_VALUE) {
            Log.e(t, "File " + file.getName() + "is too large");
            return null;
        }

        // Create the byte array to hold the data
        bytes = new byte[(int) length];

        // Read in the bytes
        int offset = 0;
        int read = 0;
        try {
            while (offset < bytes.length && read >= 0) {
                read = is.read(bytes, offset, bytes.length - offset);
                offset += read;
            }
        } catch (IOException e) {
            Log.e(t, "Cannot read " + file.getName());
            e.printStackTrace();
            return null;
        }

        // Ensure all the bytes have been read in
        if (offset < bytes.length) {
            try {
                throw new IOException("Could not completely read file " + file.getName());
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }

        return bytes;

    } catch (FileNotFoundException e) {
        Log.e(t, "Cannot find " + file.getName());
        e.printStackTrace();
        return null;

    } finally {
        // Close the input stream
        try {
            is.close();
        } catch (IOException e) {
            Log.e(t, "Cannot close input stream for " + file.getName());
            e.printStackTrace();
            return null;
        }
    }
}

From source file:com.panoramagl.downloaders.ssl.EasySSLSocketFactory.java

private static SSLContext createEasySSLContext() throws IOException {
    try {/*from   w ww.  j av  a2s .c  o m*/
        SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null);
        return context;
    } catch (Throwable e) {
        throw new IOException(e.getMessage());
    }
}

From source file:org.andromda.android.net.EasySSLSocketFactory.java

private static SSLContext createEasySSLContext() throws IOException {
    try {//w w  w  .ja v  a 2s  .c om
        final SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, new TrustManager[] { new TrivialTrustManager() }, null);
        return context;
    } catch (final Exception e) {
        throw new IOException(e.getMessage());
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.frequency.tfidf.util.TfidfUtils.java

public static void serialize(Object object, String fileName) throws Exception {
    File file = new File(fileName);
    if (!file.exists())
        FileUtils.touch(file);/*from  w w  w.j  ava 2  s  .c om*/
    if (file.isDirectory()) {
        throw new IOException("A directory with that name exists!");
    }
    ObjectOutputStream objOut;
    objOut = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
    objOut.writeObject(object);
    objOut.flush();
    objOut.close();

}

From source file:com.github.parisoft.resty.utils.JacksonUtils.java

public static <T> T read(HttpEntity entity, TypeReference<T> reference, MediaType contentType)
        throws IOException {
    for (ProviderBase<?, ?, ?, ?> provider : DataProcessors.getInstance().values()) {
        if (provider.isReadable(reference.getClass(), reference.getType(), null, contentType)) {
            return provider.locateMapper(reference.getClass(), contentType).readValue(entity.getContent(),
                    reference);/*ww w  .  j  a v a 2s . c  o  m*/
        }
    }

    throw new IOException(String.format("no processors found for type=%s and Content-Type=%s",
            reference.getType(), contentType));
}