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:Main.java

protected static void serialiseLength(DataOutputStream os, int len, int max_length)

        throws IOException {
    if (len > max_length) {

        throw (new IOException("Invalid DHT data length: max=" + max_length + ",actual=" + len));
    }/* w w  w  .j  ava2s.  com*/

    if (max_length < 256) {

        os.writeByte(len);

    } else if (max_length < 65536) {

        os.writeShort(len);

    } else {

        os.writeInt(len);
    }
}

From source file:Main.java

public static X509Certificate getCertificateFromBlob(byte[] encoded) throws IOException {
    try {// ww w.j a  v  a 2 s .c om
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        return (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(encoded));
    } catch (GeneralSecurityException gse) {
        throw new IOException(gse);
    }
}

From source file:Main.java

public static Map<String, String> load(Reader reader) throws IOException {
    try {// www  . j a  v a  2s .  c  om
        // Load XML into JDOM Document
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db;

        db = dbf.newDocumentBuilder();

        Document doc = db.parse(new InputSource(reader));
        doc.getDocumentElement().normalize();

        Map<String, String> result = new HashMap<String, String>();
        loadFromElements(result, doc.getDocumentElement().getChildNodes(),
                new StringBuffer(doc.getDocumentElement().getNodeName()));
        return result;
    } catch (ParserConfigurationException e) {
        throw new IOException(e);
    } catch (SAXException e) {
        throw new IOException(e);
    }
}

From source file:com.opensearchserver.affinities.AffinityManager.java

public static void load(File directory) throws IOException {
    if (INSTANCE != null)
        throw new IOException("Already loaded");
    INSTANCE = new AffinityManager(directory);
}

From source file:com.fizzed.stork.launcher.Merger.java

static public void merge(List<File> configFiles, File outputFile) throws IOException {
    // validate required arguments
    if (configFiles == null || configFiles.isEmpty()) {
        throw new IllegalArgumentException("No input config files were found");
    }//  w  w  w  .  j a va  2s. c om

    if (outputFile == null) {
        throw new IOException("no output file was specified");
    }

    ConfigurationFactory factory = new ConfigurationFactory();
    JsonNode mergedNode = null;

    // parse each configuration file into a configuration object
    for (File configFile : configFiles) {
        try {
            JsonNode updateNode = factory.createConfigNode(configFile);
            if (mergedNode == null) {
                mergedNode = updateNode;
            } else {
                mergedNode = factory.mergeNodes(mergedNode, updateNode);
            }
        } catch (Exception e) {
            throw new IOException("Config file [" + configFile + "] invalid");
        }
    }

    try {
        // write merged file back out
        factory.getMapper().writeValue(outputFile, mergedNode);
        System.out.println("Wrote merged config file: " + outputFile);
    } catch (Exception e) {
        throw new IOException("Unable to cleanly write merged config");
    }
}

From source file:com.eatnumber1.util.io.IOUtils.java

public static void write(@NotNull WritableByteChannel channel, @NotNull ByteBuffer src, int expected)
        throws IOException {
    if (channel.write(src) != expected)
        throw new IOException("Did not write expected amount of data");
}

From source file:com.intel.cryptostream.utils.IOUtils.java

public static void readFully(InputStream in, byte buf[], int off, int len) throws IOException {
    int toRead = len;
    while (toRead > 0) {
        int ret = in.read(buf, off, toRead);
        if (ret < 0) {
            throw new IOException("Premature EOF from inputStream");
        }//from  w  w  w.ja v a 2  s. co m
        toRead -= ret;
        off += ret;
    }
}

From source file:Main.java

public static File getDirWithCreate(String path) throws IOException {
    File dir = new File(path);

    if (!dir.exists()) {
        if (!dir.mkdirs()) {
            throw new IOException("Can not create directory " + path);
        }/*ww w  .  ja  v  a2 s. c o  m*/
    }

    return dir;
}

From source file:com.codercowboy.photo.organizer.service.PhotoIndexer.java

public static List<Photo> indexDirectory(String directoryAbsolutePath) throws Exception {
    File directory = new File(directoryAbsolutePath);
    if (!directory.exists()) {
        throw new IOException("Directory for indexing does not exist: " + directoryAbsolutePath);
    }//from w w  w .j  a v a 2 s .  c  om
    if (!directory.canRead()) {
        throw new IOException(
                "Cannot read directory for indexing, permission denied: " + directoryAbsolutePath);
    }
    List<Photo> photos = new LinkedList<>();
    for (File f : FileUtils.listFiles(directory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) {
        //TODO: this should be externally configurable
        if (".DS_Store".equals(f.getName())) {
            continue;
        }
        photos.add(indexFile(f));
    }
    return photos;
}

From source file:Main.java

/**
 * Retrieves PID from filename with format [PREFIX][PID].[EXTENSION]
 * @param filename - the file name to parse
 * @param prefix - the prefix of the filename up to the PID
 * @return - the PID portion of the filename as an Integer
 * @throws IOException If PID can not be parsed.
 *//*from w  ww.  jav a  2s . co  m*/
public static Integer parsePID(String filename, String prefix) throws IOException {
    String pidstr = filename.substring(prefix.length(), filename.lastIndexOf(DOT));
    if (isNumber(pidstr)) {
        return Integer.valueOf(pidstr);
    } else {
        throw new IOException("Cannot parse PID from output file"); //$NON-NLS-1$
    }
}