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:net.sourceforge.floggy.maven.ZipUtils.java

/**
 * DOCUMENT ME!//from ww  w .  ja  va  2s.  c  om
*
* @param file DOCUMENT ME!
* @param directory DOCUMENT ME!
*
* @throws IOException DOCUMENT ME!
*/
public static void unzip(File file, File directory) throws IOException {
    ZipFile zipFile = new ZipFile(file);
    Enumeration entries = zipFile.entries();

    if (!directory.exists() && !directory.mkdirs()) {
        throw new IOException("Unable to create the " + directory + " directory!");
    }

    while (entries.hasMoreElements()) {
        File temp;
        ZipEntry entry = (ZipEntry) entries.nextElement();

        if (entry.isDirectory()) {
            temp = new File(directory, entry.getName());

            if (!temp.exists() && !temp.mkdirs()) {
                throw new IOException("Unable to create the " + temp + " directory!");
            }
        } else {
            temp = new File(directory, entry.getName());
            IOUtils.copy(zipFile.getInputStream(entry), new FileOutputStream(temp));
        }
    }

    zipFile.close();
}

From source file:Main.java

/**
 * Convert a DOM tree into a String using transform
 * @param domDoc                  DOM object
 * @throws java.io.IOException    I/O exception
 * @return                        XML as String
 *///from   ww w  .  j  a v  a2s  .  c  om
public static String docToString2(Document domDoc) throws IOException {
    try {
        TransformerFactory transFact = TransformerFactory.newInstance();
        Transformer trans = transFact.newTransformer();
        trans.setOutputProperty(OutputKeys.INDENT, "no");
        StringWriter sw = new StringWriter();
        Result result = new StreamResult(sw);
        trans.transform(new DOMSource(domDoc), result);
        return sw.toString();
    } catch (Exception ex) {
        throw new IOException(String.format("Error converting from doc to string %s", ex.getMessage()));
    }
}

From source file:com.github.carlomicieli.nerdmovies.utility.ImageUtils.java

private static void validateFile(MultipartFile file) throws IOException {
    String contentType = file.getContentType();
    if (!contentType.equals(MediaType.IMAGE_JPEG.toString())
            && !contentType.equals(MediaType.IMAGE_PNG.toString()))
        throw new IOException("Invalid media type");
}

From source file:net.GoTicketing.GetNecessaryCookie.java

public static void getCookie(String host, String referer, String target, Map<String, String> cookieMap) {

    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        HttpGet httpGet = new HttpGet(host + target);
        httpGet.setConfig(DEFAULT_PARAMS);

        String cookies = CookieMapToString(cookieMap);
        if (!cookies.equals(""))
            httpGet.setHeader("Cookie", cookies);

        httpGet.setHeader("Referer", host + referer);

        try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {

            //  HttpStatusCode != 200 && != 404
            if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK
                    && httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_NOT_FOUND) {
                String ErrorCode = "Response Status : " + httpResponse.getStatusLine().getStatusCode();
                throw new IOException(ErrorCode);
            }/*  w ww.java2 s.c  o m*/

            try (BufferedInputStream buff = new BufferedInputStream(httpResponse.getEntity().getContent())) {
                String hstr;
                for (Header header : httpResponse.getHeaders("Set-Cookie")) {
                    hstr = header.getValue().split(";")[0];
                    cookieMap.put(hstr.split("=", 2)[0], hstr.split("=", 2)[1]);
                }
            }
        }
    } catch (IOException ex) {
        logger.log(Level.WARNING, "Get cookie from {0} failed in exception : {1}", new Object[] { target, ex });
    }
}

From source file:com.cloudera.oryx.kmeans.common.pmml.KMeansPMML.java

public static PMML read(File f) throws IOException {
    InputStream in = IOUtils.openMaybeDecompressing(f);
    try {/*from w  ww.  j  a  v  a2s .com*/
        return read(in);
    } catch (JAXBException jaxbe) {
        throw new IOException(jaxbe);
    } catch (SAXException saxe) {
        throw new IOException(saxe);
    } finally {
        in.close();
    }
}

From source file:Main.java

/**
 * Uses a TransformerFactory with an identity transformation to convert a
 * Document into a String representation of the XML.
 *
 * @param document Document.// ww  w. j a va  2  s .  c  om
 * @return An XML String.
 * @throws IOException if an error occurs during transformation.
 */
public static String documentToString(Document document) throws IOException {
    String xml = null;

    try {
        DOMSource dom = new DOMSource(document);
        StringWriter writer = new StringWriter();
        StreamResult output = new StreamResult(writer);

        // Use Transformer to serialize a DOM
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();

        // No need for pretty printing
        transformer.setOutputProperty(OutputKeys.INDENT, INDENT_XML);

        // XML Declarations unexpected whitespace for legacy AS XMLDocument type,
        // so we always omit it. We can't tell whether one was present when
        // constructing the Document in the first place anyway...
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, OMIT_XML_DECLARATION);

        transformer.transform(dom, output);

        xml = writer.toString();
    } catch (TransformerException te) {
        throw new IOException("Error serializing Document as String: " + te.getMessageAndLocation());
    }
    return xml;
}

From source file:com.rapleaf.hank.storage.curly.CurlyReader.java

public static CurlyFilePath getLatestBase(String partitionRoot) throws IOException {
    SortedSet<CurlyFilePath> bases = Curly.getBases(partitionRoot);
    if (bases == null || bases.size() == 0) {
        throw new IOException("Could not detect any Curly base in " + partitionRoot);
    }/*ww w . j a v a  2  s  .co  m*/
    return bases.last();
}

From source file:Main.java

public static Document parse(InputStream is) throws IOException {
    try {/*from   w w w .  j  a v a  2 s  .  com*/
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setCoalescing(true);
        factory.setIgnoringComments(true);
        factory.setIgnoringElementContentWhitespace(true);
        factory.setNamespaceAware(true);
        DocumentBuilder parser = factory.newDocumentBuilder();
        InputSource in = new InputSource(is);
        return parser.parse(in);
    } catch (ParserConfigurationException e) {
        throw new IOException(e);
    } catch (SAXException e) {
        throw new IOException(e);
    }
}

From source file:com.claim.support.FtpUtil.java

public static void ftpCreateDirectoryTree(FTPClient client, String dirTree) throws IOException {

    boolean dirExists = true;

    //tokenize the string and attempt to change into each directory level.  If you cannot, then start creating.
    String[] directories = dirTree.split("/");
    for (String dir : directories) {
        if (!dir.isEmpty()) {
            if (dirExists) {
                dirExists = client.changeWorkingDirectory(dir);
            }// www  . j  a v  a  2s  . c  o m
            if (!dirExists) {
                if (!client.makeDirectory(dir)) {
                    throw new IOException("Unable to create remote directory '" + dir + "'.  error='"
                            + client.getReplyString() + "'");
                }
                if (!client.changeWorkingDirectory(dir)) {
                    throw new IOException("Unable to change into newly created remote directory '" + dir
                            + "'.  error='" + client.getReplyString() + "'");
                }
            }
        }
    }
}

From source file:com.qwazr.webapps.transaction.WebappManager.java

public synchronized static Class<? extends WebappManagerServiceInterface> load(File data_directory,
        TrackedDirectory etcTracker, File tempDirectory) throws IOException {
    if (INSTANCE != null)
        throw new IOException("Already loaded");
    ControllerManager.load(data_directory);
    StaticManager.load(data_directory);/*  ww  w.  j a v a2s  . c  o m*/
    try {
        INSTANCE = new WebappManager(etcTracker, tempDirectory);
        etcTracker.register(INSTANCE);
        return WebappManagerServiceImpl.class;
    } catch (ServerException e) {
        throw new RuntimeException(e);
    }
}