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:org.apache.hadoop.mapred.pipes.SubmitterToAccels.java

private static void setupPipesJob(JobConf conf) throws IOException {
    // default map output types to Text
    if (!getIsJavaMapper(conf)) {
        conf.setMapRunnerClass(PipesMapRunner.class);
        conf.setGPUMapRunnerClass(PipesMapRunner.class);
        // Save the user's partitioner and hook in our's.
        setJavaPartitioner(conf, conf.getPartitionerClass());
        conf.setPartitionerClass(PipesPartitioner.class);
    }/*from www  .j  a v  a2s  . co m*/
    if (!getIsJavaReducer(conf)) {
        conf.setReducerClass(PipesReducer.class);
        if (!getIsJavaRecordWriter(conf)) {
            conf.setOutputFormat(NullOutputFormat.class);
        }
    }
    String textClassname = Text.class.getName();
    setIfUnset(conf, "mapred.mapoutput.key.class", textClassname);
    setIfUnset(conf, "mapred.mapoutput.value.class", textClassname);
    setIfUnset(conf, "mapred.output.key.class", textClassname);
    setIfUnset(conf, "mapred.output.value.class", textClassname);

    // Use PipesNonJavaInputFormat if necessary to handle progress reporting
    // from C++ RecordReaders ...
    if (!getIsJavaRecordReader(conf) && !getIsJavaMapper(conf)) {
        conf.setClass("mapred.pipes.user.inputformat", conf.getInputFormat().getClass(), InputFormat.class);
        conf.setInputFormat(PipesNonJavaInputFormat.class);
    }

    String cpubin = getCPUExecutable(conf);
    String gpubin = getGPUExecutable(conf);
    if (cpubin == null || gpubin == null) {
        throw new IllegalArgumentException("No application program defined.");
    }
    // add default debug script only when executable is expressed as
    // <path>#<executable>
    if (cpubin.contains("#")) {
        DistributedCache.createSymlink(conf);
        // set default gdb commands for map and reduce task 
        String defScript = "$HADOOP_HOME/src/c++/pipes/debug/pipes-default-script";
        setIfUnset(conf, "mapred.map.task.debug.script", defScript);
        setIfUnset(conf, "mapred.reduce.task.debug.script", defScript);
    }

    if (gpubin.contains("#")) {
        DistributedCache.createSymlink(conf);
        // set default gdb commands for map and reduce task 
        String defScript = "$HADOOP_HOME/src/c++/pipes/debug/pipes-default-script";
        setIfUnset(conf, "mapred.map.task.debug.script", defScript);
        setIfUnset(conf, "mapred.reduce.task.debug.script", defScript);
    }

    URI[] fileCache = DistributedCache.getCacheFiles(conf);
    if (fileCache == null) {
        fileCache = new URI[2];
    } else {
        URI[] tmp = new URI[fileCache.length + 1];
        System.arraycopy(fileCache, 0, tmp, 1, fileCache.length);
        fileCache = tmp;
    }
    try {
        fileCache[0] = new URI(cpubin);
    } catch (URISyntaxException e) {
        IOException ie = new IOException("Problem parsing execable URI " + cpubin);
        ie.initCause(e);
        throw ie;
    }
    try {
        fileCache[1] = new URI(gpubin);
    } catch (URISyntaxException e) {
        IOException ie = new IOException("Problem parsing execable URI " + gpubin);
        ie.initCause(e);
        throw ie;
    }
    DistributedCache.setCacheFiles(fileCache, conf);
}

From source file:org.apache.hadoop.mapreduce.v2.jobhistory.FileNameIndexUtils.java

/**
 * Helper function to encode the URL of the filename of the job-history
 * log file./*from   w w w.  j  a va 2 s .c o  m*/
 * 
 * @param logFileName file name of the job-history file
 * @return URL encoded filename
 * @throws IOException
 */
public static String encodeJobHistoryFileName(String logFileName) throws IOException {
    String replacementDelimiterEscape = null;

    // Temporarily protect the escape delimiters from encoding
    if (logFileName.contains(DELIMITER_ESCAPE)) {
        replacementDelimiterEscape = nonOccursString(logFileName);

        logFileName = logFileName.replaceAll(DELIMITER_ESCAPE, replacementDelimiterEscape);
    }

    String encodedFileName = null;
    try {
        encodedFileName = URLEncoder.encode(logFileName, "UTF-8");
    } catch (UnsupportedEncodingException uee) {
        IOException ioe = new IOException();
        ioe.initCause(uee);
        ioe.setStackTrace(uee.getStackTrace());
        throw ioe;
    }

    // Restore protected escape delimiters after encoding
    if (replacementDelimiterEscape != null) {
        encodedFileName = encodedFileName.replaceAll(replacementDelimiterEscape, DELIMITER_ESCAPE);
    }

    return encodedFileName;
}

From source file:com.code4bones.utils.HttpUtils.java

private static void handleHttpConnectionException(Exception exception, String url) throws IOException {
    // Inner exception should be logged to make life easier.
    Log.e(TAG, "Url: " + url + "\n" + exception.getMessage());
    IOException e = new IOException(exception.getMessage());
    e.initCause(exception);
    throw e;/*  w ww  . j av  a 2 s .c  om*/
}

From source file:org.pixmob.fm2.util.HttpUtils.java

private static KeyStore loadCertificates(Context context) throws IOException {
    try {//from ww  w .  j  a  va 2  s .c om
        final KeyStore localTrustStore = KeyStore.getInstance("BKS");
        final InputStream in = context.getResources().openRawResource(R.raw.mykeystore);
        try {
            localTrustStore.load(in, "mysecret".toCharArray());
        } finally {
            in.close();
        }

        return localTrustStore;
    } catch (Exception e) {
        final IOException ioe = new IOException("Failed to load SSL certificates");
        ioe.initCause(e);
        throw ioe;
    }
}

From source file:uk.ac.ox.webauth.PrivateKeyManager.java

/** Convenience method. */
private static int parseInt(String data) throws IOException {
    try {// w w w.  j  a  va  2 s .  c  o m
        return Integer.parseInt(data);
    } catch (NumberFormatException nfe) {
        IOException ioe = new IOException("Could not parse '" + data + "' into an int.");
        ioe.initCause(nfe);
        throw ioe;
    }
}

From source file:uk.ac.ox.webauth.PrivateKeyManager.java

/** Convenience method. */
private static long parseLong(String data) throws IOException {
    try {/* ww  w.  java2s .c  o  m*/
        return Long.parseLong(data);
    } catch (NumberFormatException nfe) {
        IOException ioe = new IOException("Could not parse '" + data + "' into a long.");
        ioe.initCause(nfe);
        throw ioe;
    }
}

From source file:hu.javaforum.android.soap.Transport.java

/**
 * Encapsulate Exception to IOException with cause (ANDROIDSOAP-14).
 *
 * @param except The Exception instance/*from   w  w  w  . j av a  2  s.c om*/
 * @return The IOException instance
 */
protected static IOException encapsulateIOException(final Exception except) {
    final IOException ioException = except == null ? new IOException() : new IOException(except.getMessage());
    ioException.initCause(except);
    return ioException;
}

From source file:org.commoncrawl.util.shared.MMapUtils.java

/**
 * Try to unmap the buffer, this method silently fails if no support
 * for that in the JVM. On Windows, this leads to the fact,
 * that mmapped files cannot be modified or deleted.
 *//*  ww  w  .j  a  v  a  2 s  .co m*/
final static void cleanMapping(final ByteBuffer buffer) throws IOException {
    if (getUseUnmap()) {
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                public Object run() throws Exception {
                    final Method getCleanerMethod = buffer.getClass().getMethod("cleaner");
                    getCleanerMethod.setAccessible(true);
                    final Object cleaner = getCleanerMethod.invoke(buffer);
                    if (cleaner != null) {
                        cleaner.getClass().getMethod("clean").invoke(cleaner);
                    }
                    return null;
                }
            });
        } catch (PrivilegedActionException e) {
            final IOException ioe = new IOException("unable to unmap the mapped buffer");
            ioe.initCause(e.getCause());
            throw ioe;
        }
    }
}

From source file:biz.varkon.shelvesom.server.CVInfo.java

/**
 * Parses a valid XML response from the specified input stream. This method
 * must invoke parse/*from   www .ja v  a  2 s.c o  m*/
 * {@link ResponseParser#parseResponse(org.xmlpull.v1.XmlPullParser)} if the
 * XML response is valid, or throw an exception if it is not.
 * 
 * @param in
 *            The input stream containing the response sent by the web
 *            service.
 * @param responseParser
 *            The parser to use when the response is valid.
 * 
 * @throws java.io.IOException
 */
public static void parseResponse(InputStream in, ResponseParser responseParser,
        IOUtilities.inputTypes inputType) throws IOException {
    final XmlPullParser parser = Xml.newPullParser();
    try {
        parser.setInput(new InputStreamReader(in));

        int type;
        while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
            // Empty
        }

        if (type != XmlPullParser.START_TAG) {
            throw new InflateException(parser.getPositionDescription() + ": No start tag found!");
        }

        String name;
        boolean valid = false;
        final int topDepth = parser.getDepth();

        while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > topDepth)
                && type != XmlPullParser.END_DOCUMENT) {

            if (type != XmlPullParser.START_TAG) {
                continue;
            }

            name = parser.getName();

            if (RESPONSE_TAG_RESULTS.equals(name)) {
                valid = true;
                break;
            }
        }

        if (valid)
            responseParser.parseResponse(parser);

    } catch (XmlPullParserException e) {
        final IOException ioe = new IOException("Could not parse the response");
        ioe.initCause(e);
        throw ioe;
    }
}

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

public static void concurrentVisitReferencedFiles(final Configuration conf, final FileSystem fs,
        final SnapshotManifest manifest, final StoreFileVisitor visitor) throws IOException {
    final SnapshotDescription snapshotDesc = manifest.getSnapshotDescription();
    final Path snapshotDir = manifest.getSnapshotDir();

    List<SnapshotRegionManifest> regionManifests = manifest.getRegionManifests();
    if (regionManifests == null || regionManifests.size() == 0) {
        LOG.debug("No manifest files present: " + snapshotDir);
        return;/*from   w  ww.  j a  v a  2 s  .c om*/
    }

    ExecutorService exec = SnapshotManifest.createExecutor(conf, "VerifySnapshot");
    final ExecutorCompletionService<Void> completionService = new ExecutorCompletionService<Void>(exec);
    try {
        for (final SnapshotRegionManifest regionManifest : regionManifests) {
            completionService.submit(new Callable<Void>() {
                @Override
                public Void call() throws IOException {
                    visitRegionStoreFiles(regionManifest, visitor);
                    return null;
                }
            });
        }
        try {
            for (int i = 0; i < regionManifests.size(); ++i) {
                completionService.take().get();
            }
        } catch (InterruptedException e) {
            throw new InterruptedIOException(e.getMessage());
        } catch (ExecutionException e) {
            if (e.getCause() instanceof CorruptedSnapshotException) {
                throw new CorruptedSnapshotException(e.getCause().getMessage(), snapshotDesc);
            } else {
                IOException ex = new IOException();
                ex.initCause(e.getCause());
                throw ex;
            }
        }
    } finally {
        exec.shutdown();
    }
}