Example usage for java.io IOException initCause

List of usage examples for java.io IOException initCause

Introduction

In this page you can find the example usage for java.io IOException initCause.

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:com.digitalpebble.behemoth.solr.LucidWorksWriter.java

public static IOException makeIOException(SolrServerException e) {
    final IOException ioe = new IOException();
    ioe.initCause(e);
    return ioe;/*from   w  w w . j  a v a 2 s  .  c  o  m*/
}

From source file:org.opensolaris.opengrok.history.RCSRepository.java

/**
 * Wrap a {@code Throwable} in an {@code IOException} and return it.
 *///from  w w w.  j  av  a  2 s . c om
static IOException wrapInIOException(String message, Throwable t) {
    // IOException's constructor takes a Throwable, but only in JDK 6
    IOException ioe = new IOException(message + ": " + t.getMessage());
    ioe.initCause(t);
    return ioe;
}

From source file:network.module.transaction.HttpUtils.java

private static void handleHttpConnectionException(Exception exception, String url) throws IOException {
    Log.e(TAG, "Url: " + url + "\n" + exception.getMessage());
    IOException e = new IOException(exception.getMessage());
    e.initCause(exception);
    throw e;//  w  ww .j ava 2  s  .  co  m
}

From source file:com.atlassian.labs.bamboo.git.edu.nyu.cs.javagit.client.cli.ProcessUtilities.java

/**
 * Start a process.//from  www . j av  a  2  s  . co  m
 *
 * @param pb
 *          The <code>ProcessBuilder</code> to use to start the process.
 * @return The started process.
 * @exception IOException
 *              An <code>IOException</code> is thrown if there is trouble starting the
 *              sub-process.
 */
public static Process startProcess(ProcessBuilder pb) throws IOException {
    try {
        return pb.start();
    } catch (IOException e) {
        IOException toThrow = new IOException(ExceptionMessageMap.getMessage("020100"));
        toThrow.initCause(e);
        throw toThrow;
    }
}

From source file:org.apache.tez.mapreduce.lib.MRInputUtils.java

@SuppressWarnings("unchecked")
public static InputSplit getOldSplitDetailsFromDisk(TaskSplitIndex splitMetaInfo, JobConf jobConf,
        TezCounter splitBytesCounter) throws IOException {
    Path file = new Path(splitMetaInfo.getSplitLocation());
    FileSystem fs = FileSystem.getLocal(jobConf);
    file = fs.makeQualified(file);/*from w w  w  .  j  ava  2  s .c  o  m*/
    LOG.info("Reading input split file from : " + file);
    long offset = splitMetaInfo.getStartOffset();

    FSDataInputStream inFile = fs.open(file);
    inFile.seek(offset);
    String className = Text.readString(inFile);
    Class<org.apache.hadoop.mapred.InputSplit> cls;
    try {
        cls = (Class<org.apache.hadoop.mapred.InputSplit>) jobConf.getClassByName(className);
    } catch (ClassNotFoundException ce) {
        IOException wrap = new IOException("Split class " + className + " not found");
        wrap.initCause(ce);
        throw wrap;
    }
    SerializationFactory factory = new SerializationFactory(jobConf);
    Deserializer<org.apache.hadoop.mapred.InputSplit> deserializer = (Deserializer<org.apache.hadoop.mapred.InputSplit>) factory
            .getDeserializer(cls);
    deserializer.open(inFile);
    org.apache.hadoop.mapred.InputSplit split = deserializer.deserialize(null);
    long pos = inFile.getPos();
    if (splitBytesCounter != null) {
        splitBytesCounter.increment(pos - offset);
    }
    inFile.close();
    return split;
}

From source file:org.apache.tez.mapreduce.lib.MRInputUtils.java

@SuppressWarnings("unchecked")
public static org.apache.hadoop.mapreduce.InputSplit getNewSplitDetailsFromDisk(TaskSplitIndex splitMetaInfo,
        JobConf jobConf, TezCounter splitBytesCounter) throws IOException {
    Path file = new Path(splitMetaInfo.getSplitLocation());
    long offset = splitMetaInfo.getStartOffset();

    // Split information read from local filesystem.
    FileSystem fs = FileSystem.getLocal(jobConf);
    file = fs.makeQualified(file);/*from  w  ww  .  j  a  va 2s  .  c om*/
    LOG.info("Reading input split file from : " + file);
    FSDataInputStream inFile = fs.open(file);
    inFile.seek(offset);
    String className = Text.readString(inFile);
    Class<org.apache.hadoop.mapreduce.InputSplit> cls;
    try {
        cls = (Class<org.apache.hadoop.mapreduce.InputSplit>) jobConf.getClassByName(className);
    } catch (ClassNotFoundException ce) {
        IOException wrap = new IOException("Split class " + className + " not found");
        wrap.initCause(ce);
        throw wrap;
    }
    SerializationFactory factory = new SerializationFactory(jobConf);
    Deserializer<org.apache.hadoop.mapreduce.InputSplit> deserializer = (Deserializer<org.apache.hadoop.mapreduce.InputSplit>) factory
            .getDeserializer(cls);
    deserializer.open(inFile);
    org.apache.hadoop.mapreduce.InputSplit split = deserializer.deserialize(null);
    long pos = inFile.getPos();
    if (splitBytesCounter != null) {
        splitBytesCounter.increment(pos - offset);
    }
    inFile.close();
    return split;
}

From source file:org.apache.hadoop.hbase.snapshot.SnapshotManifestV2.java

static List<SnapshotRegionManifest> loadRegionManifests(final Configuration conf, final Executor executor,
        final FileSystem fs, final Path snapshotDir, final SnapshotDescription desc) throws IOException {
    FileStatus[] manifestFiles = FSUtils.listStatus(fs, snapshotDir, new PathFilter() {
        @Override/*w w  w. j  a  va 2 s  . c  o  m*/
        public boolean accept(Path path) {
            return path.getName().startsWith(SNAPSHOT_MANIFEST_PREFIX);
        }
    });

    if (manifestFiles == null || manifestFiles.length == 0)
        return null;

    final ExecutorCompletionService<SnapshotRegionManifest> completionService = new ExecutorCompletionService<SnapshotRegionManifest>(
            executor);
    for (final FileStatus st : manifestFiles) {
        completionService.submit(new Callable<SnapshotRegionManifest>() {
            @Override
            public SnapshotRegionManifest call() throws IOException {
                FSDataInputStream stream = fs.open(st.getPath());
                try {
                    return SnapshotRegionManifest.parseFrom(stream);
                } finally {
                    stream.close();
                }
            }
        });
    }

    ArrayList<SnapshotRegionManifest> regionsManifest = new ArrayList<SnapshotRegionManifest>(
            manifestFiles.length);
    try {
        for (int i = 0; i < manifestFiles.length; ++i) {
            regionsManifest.add(completionService.take().get());
        }
    } catch (InterruptedException e) {
        throw new InterruptedIOException(e.getMessage());
    } catch (ExecutionException e) {
        IOException ex = new IOException();
        ex.initCause(e.getCause());
        throw ex;
    }
    return regionsManifest;
}

From source file:org.uimafit.factory.JCasFactory.java

/**
 * This method takes a JCas, resets it, and loads it with the contents of an XMI or XCAS input
 * stream//from  w w w  .j a  va2 s .c  om
 *
 * @param xmlInputStream
 *            should contain the contents of a serialized CAS in the form of XMI or XCAS XML
 * @param isXmi
 *            if true, than assume XMI format. Otherwise, assume XCAS.
 */
public static void loadJCas(JCas jCas, InputStream xmlInputStream, boolean isXmi) throws IOException {
    jCas.reset();
    try {
        CAS cas = jCas.getCas();
        if (isXmi) {
            XmiCasDeserializer.deserialize(xmlInputStream, cas);
        } else {
            XCASDeserializer.deserialize(xmlInputStream, cas);
        }
    } catch (SAXException e) {
        IOException ioe = new IOException(e.getMessage());
        ioe.initCause(e);
        throw ioe; // NOPMD
        // If we were using Java 1.6 and add the wrapped exception to the IOException
        // constructor, we would not get a warning here
    } finally {
        IOUtils.closeQuietly(xmlInputStream);
    }
}

From source file:org.znerd.yaff.MultipartServletRequestWrapper.java

/**
 * Constructs a new <code>IOException</code> with the specified cause
 * exception./*from  w  ww . j av a  2s.  c  o m*/
 *
 * @param message
 *    the detail message, can be <code>null</code>.
 *
 * @param cause
 *    the cause exception, can be <code>null</code>.
 *
 * @return
 *    a correctly initialized {@link IOException}, never <code>null</code>.
 */
static final IOException newIOException(String message, Throwable cause) {
    IOException e = new IOException(message);
    if (cause != null) {
        e.initCause(cause);
    }
    return e;
}

From source file:com.atlassian.labs.bamboo.git.edu.nyu.cs.javagit.client.cli.ProcessUtilities.java

/**
 * Reads the output from the process and prints it to stdout.
 *
 * @param p/*w  w w  . j a v a 2 s  .com*/
 *          The process from which to read the output.
 * @exception IOException
 *              An <code>IOException</code> is thrown if there is trouble reading input from the
 *              sub-process.
 */
public static void getProcessOutput(Process p, IParser parser) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    while (true) {
        try {
            String str = br.readLine();
            if (null == str) {
                break;
            }
            parser.parseLine(str);
            LOG.debug("  " + str);
        } catch (IOException e) {
            /*
             * TODO: add logging of any information already read from the InputStream. -- jhl388
             * 06.14.2008
             */
            IOException toThrow = new IOException(ExceptionMessageMap.getMessage("020101"));
            toThrow.initCause(e);
            throw toThrow;
        }
    }
}