Example usage for java.io IOException getCause

List of usage examples for java.io IOException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.apache.hawq.pxf.service.ReadBridge.java

/**
 * Fetches next object from file and turn it into a record that the HAWQ
 * backend can process.//from   w  w w  .ja v  a 2 s.c o m
 */
@Override
public Writable getNext() throws Exception {
    Writable output = null;
    OneRow onerow = null;

    if (!outputQueue.isEmpty()) {
        return outputQueue.pop();
    }

    try {
        while (outputQueue.isEmpty()) {
            onerow = fileAccessor.readNextObject();
            if (onerow == null) {
                fileAccessor.closeForRead();
                output = outputBuilder.getPartialLine();
                if (output != null) {
                    LOG.warn("A partial record in the end of the fragment");
                }
                // if there is a partial line, return it now, otherwise it
                // will return null
                return output;
            }

            // we checked before that outputQueue is empty, so we can
            // override it.
            outputQueue = outputBuilder.makeOutput(fieldsResolver.getFields(onerow));
            if (!outputQueue.isEmpty()) {
                output = outputQueue.pop();
                break;
            }
        }
    } catch (IOException ex) {
        if (!isDataException(ex)) {
            fileAccessor.closeForRead();
            throw ex;
        }
        output = outputBuilder.getErrorOutput(ex);
    } catch (BadRecordException ex) {
        String row_info = "null";
        if (onerow != null) {
            row_info = onerow.toString();
        }
        if (ex.getCause() != null) {
            LOG.debug("BadRecordException " + ex.getCause().toString() + ": " + row_info);
        } else {
            LOG.debug(ex.toString() + ": " + row_info);
        }
        output = outputBuilder.getErrorOutput(ex);
    } catch (Exception ex) {
        fileAccessor.closeForRead();
        throw ex;
    }

    return output;
}

From source file:org.osaf.cosmo.atom.provider.PreferencesCollectionAdapter.java

public ResponseContext putEntry(RequestContext request) {
    PreferenceTarget target = (PreferenceTarget) request.getTarget();
    User user = target.getUser();//  w ww .  java 2 s . c om
    Preference pref = target.getPreference();
    if (log.isDebugEnabled())
        log.debug("upudating preference " + pref.getKey() + " for user " + user.getUsername());

    ResponseContext frc = checkEntryWritePreconditions(request);
    if (frc != null)
        return frc;

    try {
        Preference newpref = readPreference(request);

        if (user.getPreference(newpref.getKey()) != null && !user.getPreference(newpref.getKey()).equals(pref))
            return ProviderHelper.conflict(request, "Preference exists");

        String oldKey = pref.getKey();
        pref.setKey(newpref.getKey());
        pref.setValue(newpref.getValue());

        user = userService.updateUser(user);

        ServiceLocator locator = createServiceLocator(request);
        PreferencesFeedGenerator generator = createPreferencesFeedGenerator(locator);
        Entry entry = generator.generateEntry(pref);

        boolean locationChanged = !oldKey.equals(pref.getKey());
        return updated(request, entry, pref, locator, locationChanged);
    } catch (IOException e) {
        String reason = "Unable to read request content: " + e.getMessage();
        log.error(reason, e);
        return ProviderHelper.servererror(request, reason, e);
    } catch (ValidationException e) {
        String msg = "Invalid entry: " + e.getMessage();
        if (e.getCause() != null)
            msg += e.getCause().getMessage();
        return ProviderHelper.badrequest(request, msg);
    } catch (GeneratorException e) {
        String reason = "Unknown entry generation error: " + e.getMessage();
        log.error(reason, e);
        return ProviderHelper.servererror(request, reason, e);
    }
}

From source file:org.talend.mdm.bulkload.client.InputStreamMergerTest.java

public void testSimpleReadPusherFirstWithError() throws Exception {
    InputStreamMerger bis = new InputStreamMerger();
    String testString = "test"; //$NON-NLS-1$

    // Create a reader for the stream
    ReaderWithErrorsRunnable reader = new ReaderWithErrorsRunnable(bis, 4);
    // Create a "pusher", a thread that will put a new stream
    Runnable pusher = new PusherRunnable(bis, testString, 20);

    // Start the test (but now the pusher starts first)
    Thread readerThread = new Thread(reader);
    Thread pusherThread = new Thread(pusher);
    pusherThread.start();//from www  .j  a  v  a 2s  . c o m
    Thread.sleep(1000);
    readerThread.start();

    // Wait for test end
    readerThread.join();
    pusherThread.join();
    assertNotNull(bis.getLastReportedFailure());
    assertEquals("Expected exception text", bis.getLastReportedFailure().getCause().getMessage()); //$NON-NLS-1$
    try {
        bis.close();
        fail("Expected an exception on close."); //$NON-NLS-1$
    } catch (IOException e) {
        assertEquals("Expected exception text", e.getCause().getCause().getMessage()); //$NON-NLS-1$
    }
    assertEquals("testtesttesttest", reader.getRebuiltString()); //$NON-NLS-1$
}

From source file:org.walkmod.gradle.providers.ClassLoaderConfigurationProvider.java

private Integer getMinAndroidSDKVersion(File projectDir) {
    File cfg = new File(projectDir, "build.gradle");
    Integer version = null;//w  w  w .ja va 2  s . c  om
    try {
        List<String> cfgContent = FileUtils.readLines(cfg);
        Iterator<String> it = cfgContent.iterator();
        while (it.hasNext() && version == null) {
            String line = it.next();
            int index = line.indexOf("minSdkVersion ");
            if (index != -1) {

                version = Integer.parseInt(line.substring(index + "minSdkVersion ".length()).trim());
            }
        }

    } catch (IOException e) {
        throw new ConfigurationException("Error reading the build.gradle", e.getCause());
    }
    return version;
}

From source file:org.osaf.cosmo.atom.provider.SubscriptionCollectionAdapter.java

public ResponseContext postEntry(RequestContext request) {
    SubscriptionsTarget target = (SubscriptionsTarget) request.getTarget();
    User user = target.getUser();/*from w  w  w . j  a  v a  2s .  c  om*/

    ResponseContext frc = checkEntryWritePreconditions(request);
    if (frc != null)
        return frc;

    try {
        CollectionSubscription sub = readSubscription(request);

        if (user.getSubscription(sub.getDisplayName()) != null)
            return ProviderHelper.conflict(request, "Named subscription exists");

        if (log.isDebugEnabled())
            log.debug("creating subscription " + sub.getDisplayName() + " for user " + user.getUsername());

        user.addSubscription(sub);
        user = userService.updateUser(user);

        ServiceLocator locator = createServiceLocator(request);
        SubscriptionFeedGenerator generator = createSubscriptionFeedGenerator(locator);
        Entry entry = generator.generateEntry(sub);

        return created(request, entry, sub, locator);
    } catch (IOException e) {
        String reason = "Unable to read request content: " + e.getMessage();
        log.error(reason, e);
        return ProviderHelper.servererror(request, reason, e);
    } catch (ValidationException e) {
        String msg = "Invalid entry: " + e.getMessage();
        if (e.getCause() != null)
            msg += ": " + e.getCause().getMessage();
        return ProviderHelper.badrequest(request, msg);
    } catch (GeneratorException e) {
        String reason = "Unknown entry generation error: " + e.getMessage();
        log.error(reason, e);
        return ProviderHelper.servererror(request, reason, e);
    }
}

From source file:org.osaf.cosmo.atom.provider.SubscriptionCollectionAdapter.java

public ResponseContext putEntry(RequestContext request) {
    SubscriptionTarget target = (SubscriptionTarget) request.getTarget();
    User user = target.getUser();//from  w ww . j  av a  2  s .  co m
    CollectionSubscription sub = target.getSubscription();
    if (log.isDebugEnabled())
        log.debug("upudating subscription " + sub.getDisplayName() + " for user " + user.getUsername());

    ResponseContext frc = checkEntryWritePreconditions(request);
    if (frc != null)
        return frc;

    try {
        CollectionSubscription newsub = readSubscription(request);

        if (user.getSubscription(newsub.getDisplayName()) != null
                && !user.getSubscription(newsub.getDisplayName()).equals(sub))
            return ProviderHelper.conflict(request, "Named subscription exists");

        String oldName = sub.getDisplayName();
        sub.setDisplayName(newsub.getDisplayName());
        sub.setCollectionUid(newsub.getCollectionUid());
        sub.setTicketKey(newsub.getTicketKey());

        user = userService.updateUser(user);

        ServiceLocator locator = createServiceLocator(request);
        SubscriptionFeedGenerator generator = createSubscriptionFeedGenerator(locator);
        Entry entry = generator.generateEntry(sub);

        boolean locationChanged = !oldName.equals(sub.getDisplayName());
        return updated(request, entry, sub, locator, locationChanged);
    } catch (IOException e) {
        String reason = "Unable to read request content: " + e.getMessage();
        log.error(reason, e);
        return ProviderHelper.servererror(request, reason, e);
    } catch (ValidationException e) {
        String msg = "Invalid entry: " + e.getMessage();
        if (e.getCause() != null)
            log.error(msg, e.getCause());
        return ProviderHelper.badrequest(request, msg);
    } catch (GeneratorException e) {
        String reason = "Unknown entry generation error: " + e.getMessage();
        log.error(reason, e);
        return ProviderHelper.servererror(request, reason, e);
    }
}

From source file:com.inmobi.conduit.distcp.tools.mapred.CopyMapper.java

private void handleFailures(IOException exception, FileStatus sourceFileStatus, Path target, Context context)
        throws IOException, InterruptedException {
    LOG.error("Failure in copying " + sourceFileStatus.getPath() + " to " + target, exception);

    if (ignoreFailures && exception.getCause() instanceof RetriableFileCopyCommand.CopyReadException) {
        incrementCounter(context, Counter.PATHS_FAILED, 1);
        incrementCounter(context, Counter.BYTES_FAILED, sourceFileStatus.getLen());
        context.write(null, new Text(
                "FAIL: " + sourceFileStatus.getPath() + " - " + StringUtils.stringifyException(exception)));
    } else/*from  w  ww  .  j a  va  2  s.c  om*/
        throw exception;
}

From source file:org.walkmod.gradle.providers.ClassLoaderConfigurationProvider.java

public GradleConnector getConnector() throws ConfigurationException {
    if (connector == null) {
        connector = GradleConnector.newConnector();
        if (installationDir != null) {
            connector.useInstallation(new File(installationDir));
            if (userHomeDir != null) {
                connector.useGradleUserHomeDir(new File(userHomeDir));
            } else {
                try {
                    userHomeDir = new File(System.getProperty("user.home"), ".gradle").getCanonicalPath();
                } catch (IOException e) {
                    throw new ConfigurationException("Error resolving the working directory", e.getCause());
                }//from   w  w w  . j a  va 2s  . c om
            }
        } else {
            try {
                userHomeDir = new File(System.getProperty("user.home"), ".gradle").getCanonicalPath();
            } catch (IOException e) {
                throw new ConfigurationException("Error resolving the working directory", e.getCause());
            }
        }
        if (workingDirectory == null) {
            try {
                workingDirectory = new File(".").getCanonicalPath();
            } catch (IOException e) {
                throw new ConfigurationException("Error resolving the working directory", e.getCause());
            }
        }

        connector.forProjectDirectory(new File(workingDirectory));
    }
    return connector;
}

From source file:com.lunabeat.dooper.HadoopCluster.java

/**
 *
 * @param host//from w w w .  ja  v a 2 s . com
 * @param src
 * @param dest
 * @throws SCPException
 */
public void putFile(ClusterInstance host, String src, String dest) throws SCPException {
    try {

        Connection conn = new Connection(host.getInstance().getPublicDnsName());
        conn.connect();
        File keyfile = new File(_config.get(ClusterConfig.KEYPAIR_FILE_KEY));
        boolean isAuthenticated = conn.authenticateWithPublicKey(_config.get(ClusterConfig.USERNAME_KEY),
                keyfile, BLANK);
        if (isAuthenticated == false) {
            throw new SCPException("Authentication failed.", host);
        }
        SCPClient scp = new SCPClient(conn);
        String[] pathAndFile = splitPathAndFile(dest);
        String outFileName = pathAndFile[1].length() > 0 ? pathAndFile[1] : splitPathAndFile(src)[1];
        String fileMode = _config.get(ClusterConfig.SCP_FILE_MODE_KEY, ClusterConfig.SCP_DEFAULT_FILE_MODE);
        LOGGER.info("SCP '" + src + "' '" + outFileName + "' '" + pathAndFile[0] + "' " + fileMode);
        scp.put(src, outFileName, pathAndFile[0], fileMode);
        conn.close();
    } catch (IOException e) {
        throw new SCPException(e.getMessage(), e.getCause(), host);
    }
}