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:de.fatalix.book.importer.BookMigrator.java

public static List<File> findAllBooks(String importPath) throws IOException {
    List<File> result = new ArrayList<>();
    File importFolder = new File(importPath);
    if (!importFolder.isDirectory()) {
        throw new IOException(importFolder.getAbsolutePath() + " is not a folder!");
    }/*from   w w  w.ja v a  2  s .co m*/
    return walkTree(result, importFolder);
}

From source file:com.google.code.rptm.metadata.pmc.CommitteeInfoParser.java

public static void parse(InputStream in, CommitteeInfoVisitor visitor) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
    int state = STATE_PREAMBLE;
    int i = 0;//from  w w w .  j  ava 2  s.  co  m
    while (true) {
        String line = reader.readLine();
        i++;
        if (line == null) {
            if (state != STATE_COMPLETE) {
                throw new IOException("Unexpected end of file (state = " + state);
            } else {
                break;
            }
        } else if (state != STATE_PREAMBLE && END_MARKER.matcher(line).matches()) {
            if (state == STATE_PROJECT) {
                visitor.endProject();
            }
            state = STATE_COMPLETE;
            continue;
        } else if ((state == STATE_PROJECT || state == STATE_PROJECT_COMPLETE) && StringUtils.isBlank(line)) {
            if (state == STATE_PROJECT) {
                visitor.endProject();
                state = STATE_PROJECT_COMPLETE;
            }
            continue;
        } else if (state == STATE_PROJECT) {
            Matcher m = MEMBER_ENTRY.matcher(line);
            if (m.matches()) {
                visitor.member(m.group(1), m.group(3));
                continue;
            }
        } else if (state == STATE_PREAMBLE || state == STATE_PROJECT_COMPLETE) {
            Matcher m = PROJECT_HEADER.matcher(line);
            if (m.matches()) {
                visitor.startProject(m.group(1));
                state = STATE_PROJECT;
                continue;
            } else if (state == STATE_PREAMBLE) {
                continue;
            }
        } else if (state == STATE_COMPLETE && StringUtils.isBlank(line)) {
            continue;
        }
        throw new IOException("Unexpected content at line " + i + " (state = " + state + "): " + line);
    }
}

From source file:com.enonic.esl.io.FileUtil.java

/**
 * Returns the contents of the file in a byte array.
 *
 * @param file the file info/*from w ww.ja  v a 2s  . c o  m*/
 * @return a byte array containing the file's contents
 * @throws IOException
 */
public static byte[] getBytesFromFile(File file) throws IOException {
    InputStream is = new FileInputStream(file);

    // Get the size of the file
    long length = file.length();

    // You cannot create an array using a long type.
    // It needs to be an int type.
    // Before converting to an int type, check
    // to ensure that file is not larger than Integer.MAX_VALUE.
    if (length > Integer.MAX_VALUE) {
        // File is too large
    }

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

    // Read in the bytes
    int offset = 0;
    int numRead = 0;
    while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
        offset += numRead;
    }

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

    // Close the input stream and return bytes
    is.close();
    return bytes;
}

From source file:com.limegroup.gnutella.metadata.WMAMetaData.java

/** Sets data based on an ASF Parser. */
private void set(ASFParser data) throws IOException {
    if (data.hasVideo())
        throw new IOException("use WMV instead!");
    if (!data.hasAudio())
        throw new IOException("no audio data!");

    setTitle(data.getTitle());//w w w  .j a v  a 2  s  .c o  m
    setAlbum(data.getAlbum());
    setArtist(data.getArtist());
    setYear(data.getYear());
    setComment(data.getComment());
    setTrack(data.getTrack());
    setBitrate(data.getBitrate());
    setLength(data.getLength());
    setGenre(data.getGenre());
    setLicense(data.getCopyright());

    if (data.getLicenseInfo() != null)
        setLicenseType(data.getLicenseInfo());
}

From source file:es.molabs.io.utils.FileHelper.java

public static URL[] getFiles(URL path, boolean recursive, String... extensions) throws IOException {
    URL[] urls = null;/*from w w w . j a v a  2  s.  c  o  m*/

    try {
        Collection<File> fileCollection = FileUtils.listFiles(new File(path.toURI()), extensions, recursive);
        urls = new URL[fileCollection.size()];

        Iterator<File> iterator = fileCollection.iterator();
        int index = 0;
        while (iterator.hasNext()) {
            File file = iterator.next();

            urls[index++] = file.toURI().toURL();
        }
    } catch (URISyntaxException USe) {
        throw new IOException(USe);
    }

    return urls;
}

From source file:com.qwazr.database.TableManager.java

public static Class<? extends TableServiceInterface> load(ExecutorService executor, File dataDirectory)
        throws IOException {
    if (INSTANCE != null)
        throw new IOException("Already loaded");
    File tableDir = new File(dataDirectory, SERVICE_NAME_TABLE);
    if (!tableDir.exists())
        tableDir.mkdir();//from  w  ww  .  ja  v a  2 s  . co  m
    try {
        INSTANCE = new TableManager(executor, tableDir);
        return TableServiceImpl.class;
    } catch (ServerException e) {
        throw new RuntimeException(e);
    }
}

From source file:jp.furplag.util.commons.FileUtils.java

private static void forceMkdir(String path) throws IOException {
    if (StringUtils.isSimilarToBlank(path)) {
        throw new IOException("path must not be empty.");
    }/*from   www .  j av a 2 s .co m*/

    forceMkdir(new File(normalize(path)));
}

From source file:Main.java

/**
 * Resolves the xpath of an element./*from  w  w w  .  j  ava2  s . c  o m*/
 * 
 * @param elt
 * @return
 * @throws IOException
 */
public static final String getElementXPath(Node elt) throws IOException {
    String path = "";

    Node currentNode = elt;
    while (!(currentNode instanceof Document)) {
        Element parent = (Element) currentNode;
        if (!parent.getTagName().equals("schema")) {
            if (!parentNodeHasMoreOfThese((Element) currentNode)) {
                path = '/' + parent.getTagName() + path;
            } else {
                path = '/' + parent.getTagName() + '[' + getElementIdx(parent) + ']' + path;
            }
        } else {
            String schema = parent.getAttribute("name");
            String[] segments = path.substring(1).split(":", 2);
            return schema + ':' + segments[segments.length - 1];
        }

        currentNode = currentNode.getParentNode();
    }

    throw new IOException("Failed to parse document.");
}

From source file:info.ajaxplorer.client.http.AjxpSSLSocketFactory.java

private static SSLContext createEasySSLContext(String certKey) throws IOException {
    try {//from w  w  w. j  a  va2 s  .c om
        SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, new TrustManager[] { new AjxpSSLTrustManager(certKey) }, null);
        return context;
    } catch (Exception e) {
        throw new IOException(e.getMessage());
    }
}

From source file:de.shadowhunt.subversion.internal.AbstractPrepare.java

private static boolean extractArchive(final File zip, final File prefix) throws Exception {
    final ZipFile zipFile = new ZipFile(zip);
    final Enumeration<? extends ZipEntry> enu = zipFile.entries();
    while (enu.hasMoreElements()) {
        final ZipEntry zipEntry = enu.nextElement();

        final String name = zipEntry.getName();

        final File file = new File(prefix, name);
        if (name.charAt(name.length() - 1) == Resource.SEPARATOR_CHAR) {
            if (!file.isDirectory() && !file.mkdirs()) {
                throw new IOException("can not create directory structure: " + file);
            }/* www . ja  v  a2s . c o  m*/
            continue;
        }

        final File parent = file.getParentFile();
        if (parent != null) {
            if (!parent.isDirectory() && !parent.mkdirs()) {
                throw new IOException("can not create directory structure: " + parent);
            }
        }

        final InputStream is = zipFile.getInputStream(zipEntry);
        final FileOutputStream fos = new FileOutputStream(file);
        final byte[] bytes = new byte[1024];
        int length;
        while ((length = is.read(bytes)) >= 0) {
            fos.write(bytes, 0, length);
        }
        is.close();
        fos.close();

    }
    zipFile.close();
    return true;
}