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() 

Source Link

Document

Constructs an IOException with null as its error detail message.

Usage

From source file:com.frostwire.gui.library.M3UPlaylist.java

/**
 * @exception IOException Thrown if load failed.<p>
 *
 * Format of playlist (.m3u) files is:<br>
 * ----------------------<br>//from  w  w w.  j  a  v a2 s . com
 * #EXTM3U<br>
 * #EXTINF:numSeconds<br>
 * /path/of/file/1<br>
 * #EXTINF:numSeconds<br>
 * /path/of/file/2<br>
 * ----------------------<br>
 */
public static List<File> load(String fileName) throws IOException {
    List<File> files = new ArrayList<File>();
    File playListFile = new File(fileName);
    BufferedReader m3uFile = null;
    try {
        m3uFile = new BufferedReader(new FileReader(playListFile));
        String currLine = null;
        currLine = m3uFile.readLine();
        if (currLine == null || !(currLine.startsWith(M3U_HEADER) || currLine.startsWith(SONG_DELIM)))
            throw new IOException();
        if (currLine.startsWith(M3U_HEADER))
            currLine = m3uFile.readLine();

        for (; currLine != null; currLine = m3uFile.readLine()) {
            if (currLine.startsWith(SONG_DELIM)) {
                currLine = m3uFile.readLine();
                if (currLine == null)
                    break;
                File toAdd = new File(currLine);
                if (toAdd.exists() && !toAdd.isDirectory())
                    files.add(toAdd);
                else {
                    // try relative path to the playlist
                    toAdd = new File(playListFile.getParentFile().getAbsolutePath(), toAdd.getPath());
                    if (toAdd.exists() && !toAdd.isDirectory()
                            && FileUtils.isReallyInParentPath(playListFile.getParentFile(), toAdd))
                        files.add(toAdd);
                }
            }
        }
    } finally {
        IOUtils.closeQuietly(m3uFile);
    }
    return files;
}

From source file:Main.java

static void emitDocument(Document doc, OutputStream os, String encoding) throws IOException {
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = null;//w ww .  java 2s  .co m
    try {
        t = tf.newTransformer();
        //SF:no dtd            t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, PROPS_DTD_URI);
        t.setOutputProperty(OutputKeys.INDENT, "yes");
        t.setOutputProperty(OutputKeys.METHOD, "xml");
        t.setOutputProperty(OutputKeys.ENCODING, encoding);
    } catch (TransformerConfigurationException tce) {
        assert (false);
    }
    DOMSource doms = new DOMSource(doc);
    StreamResult sr = new StreamResult(os);
    try {
        t.transform(doms, sr);
    } catch (TransformerException te) {
        IOException ioe = new IOException();
        ioe.initCause(te);
        throw ioe;
    }
}

From source file:com.baidu.oped.apm.profiler.modifier.connector.httpclient4.DefaultHttpRequestRetryHandlerModifierTest.java

@Test
public void test() {
    DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
    IOException iOException = new IOException();
    HttpContext context = new BasicHttpContext();

    assertTrue(retryHandler.retryRequest(iOException, 1, context));
    assertTrue(retryHandler.retryRequest(iOException, 2, context));
    assertEquals(2, getCurrentSpanEvents().size());
}

From source file:Main.java

static void emitDocument(Document doc, OutputStream os, String encoding) throws IOException {
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = null;/* w  w w  .  j av  a2 s. c o m*/
    try {
        t = tf.newTransformer();
        t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, PROPS_DTD_URI);
        t.setOutputProperty(OutputKeys.INDENT, "yes");
        t.setOutputProperty(OutputKeys.METHOD, "xml");
        t.setOutputProperty(OutputKeys.ENCODING, encoding);
    } catch (TransformerConfigurationException tce) {
        assert (false);
    }
    DOMSource doms = new DOMSource(doc);
    StreamResult sr = new StreamResult(os);
    try {
        t.transform(doms, sr);
    } catch (TransformerException te) {
        IOException ioe = new IOException();
        ioe.initCause(te);
        throw ioe;
    }
}

From source file:com.orthancserver.OrthancConnection.java

private static InputStream OpenUrl(String urlString, String authentication) throws IOException {
    try {/*  w  ww .  j  ava 2  s .  c  om*/
        URL url = new URL(urlString);
        // http://blogs.deepal.org/2008/01/sending-basic-authentication-using-url.html
        URLConnection uc = url.openConnection();
        uc.setRequestProperty("Authorization", "Basic " + authentication);
        return uc.getInputStream();
    } catch (ConnectException e) {
        throw new IOException();
    }
}

From source file:com.upnext.beaconos.sdk.backend.JacksonConverter.java

@Override
public T fromBody(ResponseBody body) throws IOException {
    InputStream is = body.byteStream();
    try {/*from  w w  w  .  java 2s.  com*/
        T value = reader.readValue(is);
        if (value instanceof Validable) {
            if (!((Validable) value).isValid()) {
                throw new IOException();
            }
        }
        return value;
    } finally {
        try {
            is.close();
        } catch (IOException ignored) {
        }
    }
}