Example usage for java.io IOException setStackTrace

List of usage examples for java.io IOException setStackTrace

Introduction

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

Prototype

public void setStackTrace(StackTraceElement[] stackTrace) 

Source Link

Document

Sets the stack trace elements that will be returned by #getStackTrace() and printed by #printStackTrace() and related methods.

Usage

From source file:org.apache.pig.impl.logicalLayer.LOStore.java

/**
 * @param plan/* w w  w  . j ava  2 s .  c o  m*/
 *            LogicalPlan this operator is a part of.
 * @param key
 *            OperatorKey for this operator
 * @param outputFileSpec
 *            the file to be stored
 */
public LOStore(LogicalPlan plan, OperatorKey key, FileSpec outputFileSpec, String alias) throws IOException {
    super(plan, key);

    mOutputFile = outputFileSpec;

    // TODO
    // The code below is commented out as PigContext pulls in
    // HExecutionEngine which in turn is completely commented out
    // Also remove the commented out import org.apache.pig.impl.PigContext

    try {
        mStoreFunc = (StoreFuncInterface) PigContext.instantiateFuncFromSpec(outputFileSpec.getFuncSpec());
        this.mAlias = alias;
        this.signature = constructSignature(mAlias, outputFileSpec.getFileName(), mOutputFile.getFuncSpec());
        mStoreFunc.setStoreFuncUDFContextSignature(this.signature);
    } catch (Exception e) {
        IOException ioe = new IOException(e.getMessage());
        ioe.setStackTrace(e.getStackTrace());
        throw ioe;
    }
}

From source file:org.apache.ode.utils.DOMUtils.java

private static void throwIOException(Throwable t) throws IOException {
    IOException e = new IOException(t.getMessage());
    e.setStackTrace(t.getStackTrace());
    throw e;// ww  w  .ja va  2  s .co  m
}

From source file:com.smartitengineering.util.bean.PropertiesLocator.java

public boolean loadProperties(Properties props) throws IOException {
    boolean resourceFound = false;
    if (getSmartLocations() != null) {
        for (int i = 0; i < getSmartLocations().length; i++) {
            final String location = getSmartLocations()[i];
            InputStream is = null;
            String context = getResourceContext();
            if (StringUtils.isNotEmpty(context)) {
                if (!context.endsWith("/")) {
                    context = new StringBuilder(context).append('/').toString();
                }//  w  ww .  j a v a 2  s .c o m
            }
            String fileName = new StringBuilder(context).append(location).toString();
            if (StringUtils.isEmpty(fileName)) {
                continue;
            }
            try {
                Resource resource;
                if (isDefaultSearchEnabled()) {
                    String resourceName = new StringBuilder(fileName).append(getDefaultResourceSuffix())
                            .toString();
                    String resourcePath = new StringBuilder(CLASSPATH_RESOURCE_PREFIX).append(resourceName)
                            .toString();
                    resource = ResourceFactory.getResource(resourcePath);
                    is = attemptToLoadResource(props, resource);
                    resourceFound = closeInputStream(is) || resourceFound;
                }
                if (isClasspathSearchEnabled()) {
                    String resourcePath = new StringBuilder(CLASSPATH_RESOURCE_PREFIX).append(fileName)
                            .toString();
                    resource = ResourceFactory.getResource(resourcePath);
                    is = attemptToLoadResource(props, resource);
                    resourceFound = closeInputStream(is) || resourceFound;
                }
                if (isCurrentDirSearchEnabled()) {
                    String parent = System.getProperty("user.dir");
                    resourceFound = attempToReadRsrcFromFile(parent, fileName, resourceFound, props)
                            || resourceFound;
                }
                if (isUserHomeSearchEnabled()) {
                    String parent = System.getProperty("user.home");
                    resourceFound = attempToReadRsrcFromFile(parent, fileName, resourceFound, props)
                            || resourceFound;
                }
                if (getSearchLocations() != null) {
                    for (String searchLocation : getSearchLocations()) {
                        if (StringUtils.isNotEmpty(StringUtils.trim(searchLocation))) {
                            resourceFound = attempToReadRsrcFromFile(searchLocation, fileName, resourceFound,
                                    props) || resourceFound;
                        }
                    }
                }
            } catch (Exception ex) {
                IOException exception = new IOException();
                exception.setStackTrace(ex.getStackTrace());
                throw exception;
            } finally {
                closeInputStream(is);
            }
        }
    }
    return resourceFound;
}

From source file:com.oakesville.mythling.util.HttpHelper.java

private void rethrow(IOException ex, String msgPrefix) throws IOException {
    if (msgPrefix == null) {
        throw ex;
    } else {/*  w  ww  . j  a  v a 2s.c om*/
        IOException re = new IOException(msgPrefix + ": " + ex.getMessage());
        re.setStackTrace(ex.getStackTrace());
        throw re;
    }
}

From source file:org.apache.pig.impl.logicalLayer.LOLoad.java

public void setInputFile(FileSpec inputFileSpec) throws IOException {
    try {//from  w  w w. j  a v a  2  s .c  om
        mLoadFunc = (LoadFunc) PigContext.instantiateFuncFromSpec(inputFileSpec.getFuncSpec());
    } catch (ClassCastException cce) {
        log.error(inputFileSpec.getFuncSpec() + " should implement the LoadFunc interface.");
        IOException ioe = new IOException(cce.getMessage());
        ioe.setStackTrace(cce.getStackTrace());
        throw ioe;
    } catch (Exception e) {
        IOException ioe = new IOException(e.getMessage());
        ioe.setStackTrace(e.getStackTrace());
        throw ioe;
    }
    mInputFileSpec = inputFileSpec;
}

From source file:org.apache.pig.backend.hadoop.executionengine.mapreduceExec.PigMapReduce.java

/**
 * Nothing happens here.//from   w  w w.ja  v a  2  s .  c om
 */
public void close() throws IOException {
    try {
        if (evalPipe != null)
            evalPipe.finishPipe();
    } catch (Throwable t) {
        log.error(t);

        // Convert to IOException to ensure Hadoop handles it correctly ...
        IOException ioe = new IOException(t.getMessage());
        ioe.setStackTrace(t.getStackTrace());
        throw ioe;
    }
}

From source file:org.apache.pig.backend.hadoop.executionengine.mapreduceExec.PigMapReduce.java

public void reduce(Tuple key, Iterator<IndexedTuple> values,
        OutputCollector<WritableComparable, Writable> output, Reporter reporter) throws IOException {

    PigMapReduce.reporter = reporter;/*  w w  w  . ja v a 2s  . c  o  m*/

    try {
        oc = output;
        if (evalPipe == null) {
            setupReducePipe(properties);
        }

        DataBag[] bags = new DataBag[inputCount];
        Datum groupName = key.getField(0);
        Tuple t = new Tuple(1 + inputCount);
        t.setField(0, groupName);
        for (int i = 1; i < 1 + inputCount; i++) {
            bags[i - 1] = BagFactory.getInstance().newDefaultBag();
            t.setField(i, bags[i - 1]);
        }

        while (values.hasNext()) {
            IndexedTuple it = values.next();
            t.getBagField(it.index + 1).add(it.toTuple());
        }

        for (int i = 0; i < inputCount; i++) {
            if (isInner[i] && t.getBagField(1 + i).size() == 0)
                return;
        }

        evalPipe.add(t);
    } catch (Throwable tr) {
        log.error(tr);

        // Convert to IOException to ensure Hadoop handles it correctly ...
        IOException ioe = new IOException(tr.getMessage());
        ioe.setStackTrace(tr.getStackTrace());
        throw ioe;
    }
}

From source file:org.nuxeo.ecm.core.io.impl.plugins.NuxeoArchiveReader.java

private Document loadXML(ZipEntry entry) throws IOException {
    try {/*from   ww  w .j a v  a2 s.c o m*/
        // the SAXReader is closing the stream so that we need to copy the
        // content somewhere
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        if (zipFile != null) {
            FileUtils.copy(zipFile.getInputStream(entry), baos);
        } else if (file != null) {
            ZipEntrySource src = new ZipEntrySource(file, entry.getName());
            FileUtils.copy(src.getStream(), baos);
        } else {
            FileUtils.copy(in, baos);
        }
        return new SAXReader().read(new ByteArrayInputStream(baos.toByteArray()));
    } catch (DocumentException e) {
        IOException ioe = new IOException(
                "Failed to read zip entry " + entry.getName() + ": " + e.getMessage());
        ioe.setStackTrace(e.getStackTrace());
        throw ioe;
    }
}

From source file:org.apache.maven.plugins.linkcheck.SiteInvoker.java

/**
 * Invoke Maven for the <code>site</code> phase for a temporary Maven project using
 * <code>tmpReportingOutputDirectory</code> as <code>${project.reporting.outputDirectory}</code>.
 * This is a workaround to be sure that all site files have been correctly generated.
 * <br/>/*w ww. j av  a  2s .  co m*/
 * <b>Note 1</b>: the Maven Home should be defined in the <code>maven.home</code> Java system property
 * or defined in <code>M2_HOME</code> system env variables.
 * <b>Note 2</be>: we can't use <code>siteOutputDirectory</code> param from site plugin because some plugins
 * <code>${project.reporting.outputDirectory}</code> in their conf.
 *
 * @param project the MavenProject to invoke the site on. Not null.
 * @param tmpReportingOutputDirectory not null
 * @throws IOException if any
 */
public void invokeSite(MavenProject project, File tmpReportingOutputDirectory) throws IOException {
    String mavenHome = getMavenHome();
    if (StringUtils.isEmpty(mavenHome)) {
        getLog().error("Could NOT invoke Maven because no Maven Home is defined. "
                + "You need to set the M2_HOME system env variable or a 'maven.home' Java system property.");
        return;
    }

    // invoker site parameters
    List goals = Collections.singletonList("site");
    Properties properties = new Properties();
    properties.put("linkcheck.skip", "true"); // to stop recursion

    File invokerLog = FileUtils.createTempFile("invoker-site-plugin", ".txt",
            new File(project.getBuild().getDirectory()));

    // clone project and set a new reporting output dir
    MavenProject clone;
    try {
        clone = (MavenProject) project.clone();
    } catch (CloneNotSupportedException e) {
        IOException ioe = new IOException("CloneNotSupportedException: " + e.getMessage());
        ioe.setStackTrace(e.getStackTrace());
        throw ioe;
    }

    // MLINKCHECK-1
    if (clone.getOriginalModel().getReporting() == null) {
        clone.getOriginalModel().setReporting(new Reporting());
    }

    clone.getOriginalModel().getReporting().setOutputDirectory(tmpReportingOutputDirectory.getAbsolutePath());
    List profileIds = getActiveProfileIds(clone);

    // create the original model as tmp pom file for the invoker
    File tmpProjectFile = FileUtils.createTempFile("pom", ".xml", project.getBasedir());
    Writer writer = null;
    try {
        writer = WriterFactory.newXmlWriter(tmpProjectFile);
        clone.writeOriginalModel(writer);
    } finally {
        IOUtil.close(writer);
    }

    // invoke it
    try {
        invoke(tmpProjectFile, invokerLog, mavenHome, goals, profileIds, properties);
    } finally {
        if (!getLog().isDebugEnabled()) {
            tmpProjectFile.delete();
        }
    }
}

From source file:org.apache.pig.shock.SSHSocketImplFactory.java

@Override
protected void connect(SocketAddress address, int timeout) throws IOException {
    try {/*from ww w . ja va2  s .  c om*/
        if (!session.isConnected()) {
            session.connect();
        }
        channel = (ChannelDirectTCPIP) session.openChannel("direct-tcpip");
        //is = channel.getInputStream();
        //os = channel.getOutputStream();
        channel.setHost(((InetSocketAddress) address).getHostName());
        channel.setPort(((InetSocketAddress) address).getPort());
        channel.setOrgPort(22);
        is = new PipedInputStream();
        os = new PipedOutputStream();
        channel.setInputStream(new PipedInputStream((PipedOutputStream) os));
        channel.setOutputStream(new PipedOutputStream((PipedInputStream) is));
        channel.connect();
        if (!channel.isConnected()) {
            log.error("Not connected");
        }
        if (channel.isEOF()) {
            log.error("EOF");
        }
    } catch (JSchException e) {
        log.error(e);
        IOException newE = new IOException(e.getMessage());
        newE.setStackTrace(e.getStackTrace());
        throw newE;
    }
}