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.solr.client.solrj.io.stream.eval.ConversionEvaluatorsTest.java

@Test
public void testInvalidExpression() throws Exception {

    StreamEvaluator evaluator;//from  www  . ja v a2 s.  c o  m

    try {
        evaluator = factory.constructEvaluator("convert(inches)");
        StreamContext streamContext = new StreamContext();
        evaluator.setStreamContext(streamContext);
        assertTrue(false);
    } catch (IOException e) {
        assertTrue(e.getCause().getCause().getMessage()
                .contains("Invalid expression convert(inches) - expecting 3 value but found 1"));
    }

    try {
        evaluator = factory.constructEvaluator("convert(inches, yards, 3)");
        StreamContext streamContext = new StreamContext();
        evaluator.setStreamContext(streamContext);
        Tuple tuple = new Tuple(new HashMap());
        evaluator.evaluate(tuple);
        assertTrue(false);
    } catch (IOException e) {
        assertTrue(
                e.getCause().getCause().getMessage().contains("No conversion available from INCHES to YARDS"));
    }
}

From source file:de.cuseb.bilderbuch.images.GoogleImageSearch.java

@Override
public List<Image> searchImages(String query) throws ImageSearchException {

    try {/*from w  w  w. j  a  v a 2s .  c o  m*/
        Customsearch customsearch = getCustomsearch();
        Customsearch.Cse.List list = customsearch.cse().list(query);
        list.setKey(key);
        list.setCx(cx);
        list.setSearchType("image");
        list.setImgSize("xlarge");
        list.setImgType("photo");

        Search results = list.execute();
        List<Image> images = new ArrayList<Image>();

        for (Result result : results.getItems()) {
            Image image = new Image();
            image.setSource("google");
            image.setUrl(result.getLink());
            image.setTitle(result.getTitle());
            images.add(image);
        }
        return images;

    } catch (IOException e) {
        throw new ImageSearchException(e.getMessage(), e.getCause());
    }
}

From source file:dark.robot.analyzer.common.loader.FileLoader.java

/**
 * Returns all the lines in the input source
 *
 * @param source text input source/*from  ww w  .j a  v  a 2s.  c o m*/
 * @return An array of lines
 * @throws LoaderException if an {@code IOException} happened at read a line
 * @since 1.0.0
 */
protected String[] load(BufferedReader source) {
    StringBuilder content = new StringBuilder();
    String line;

    try {
        try {
            while ((line = source.readLine()) != null) {
                content.append(line);
                content.append(LineSeparator);
            }

        } finally {
            source.close();
        }
    } catch (IOException e) {
        throw new LoaderException(e.getMessage(), e.getCause());
    }

    return content.toString().split(LineSeparator);
}

From source file:gobblin.runtime.cli.ConstructorAndPublicMethodsCliObjectFactoryTest.java

@Test
public void test() throws Exception {
    MyFactory factory = new MyFactory();
    MyObject object;/*from  w  ww  .ja v a 2s  .  c  o  m*/

    try {
        // Try to build object with missing constructor argument, which is required
        object = factory.buildObject(new String[] {}, 0, false, "usage");
        Assert.fail();
    } catch (IOException exc) {
        // Expected
        Assert.assertEquals(exc.getCause().getClass(), MissingOptionException.class);
    }

    object = factory.buildObject(new String[] { "-myArg", "required" }, 0, false, "usage");
    Assert.assertEquals(object.required, "required");
    Assert.assertNull(object.string1);
    Assert.assertNull(object.string2);

    object = factory.buildObject(new String[] { "-setString1", "str1", "-myArg", "required" }, 0, false,
            "usage");
    Assert.assertEquals(object.required, "required");
    Assert.assertEquals(object.string1, "str1");
    Assert.assertNull(object.string2);

    object = factory.buildObject(new String[] { "-foo", "bar", "-myArg", "required" }, 0, false, "usage");
    Assert.assertEquals(object.required, "required");
    Assert.assertEquals(object.string2, "bar");
    Assert.assertNull(object.string1);

    object = factory.buildObject(new String[] { "-foo", "bar", "-setString1", "str1", "-myArg", "required" }, 0,
            false, "usage");
    Assert.assertEquals(object.required, "required");
    Assert.assertEquals(object.string2, "bar");
    Assert.assertEquals(object.string1, "str1");
}

From source file:com.alibaba.jstorm.yarn.utils.JStormUtils.java

public static String launchProcess(final String command, final List<String> cmdlist,
        final Map<String, String> environment, boolean backend) throws IOException {
    if (backend) {
        new Thread(new Runnable() {
            @Override//from ww  w  . ja  v a 2s .co m
            public void run() {
                List<String> cmdWrapper = new ArrayList<String>();

                cmdWrapper.add("nohup");
                cmdWrapper.addAll(cmdlist);
                cmdWrapper.add("&");

                try {
                    launchProcess(cmdWrapper, environment);
                } catch (IOException e) {
                    LOG.error("Failed to run nohup " + command + " &," + e.getCause(), e);
                }
            }
        }).start();
        return null;
    } else {
        try {
            Process process = launchProcess(cmdlist, environment);

            StringBuilder sb = new StringBuilder();
            String output = JStormUtils.getOutput(process.getInputStream());
            String errorOutput = JStormUtils.getOutput(process.getErrorStream());
            sb.append(output);
            sb.append("\n");
            sb.append(errorOutput);

            int ret = process.waitFor();
            if (ret != 0) {
                LOG.warn(command + " is terminated abnormally. ret={}, str={}", ret, sb.toString());
            }
            return sb.toString();
        } catch (Throwable e) {
            LOG.error("Failed to run " + command + ", " + e.getCause(), e);
        }

        return "";
    }
}

From source file:org.alfresco.rest.framework.tools.RequestReader.java

/**
 * Extracts the body contents from the request as a List, the JSON can be an array or just a single value without the [] symbols
 *
 * @param req          the request//w w  w  .j  a v  a  2  s .  c  o m
 * @param jsonHelper   Jackson Helper
 * @param requiredType the type to return (without the List param)
 * @return A List of "Object" as the required type
 */
default <T> List<T> extractJsonContentAsList(WebScriptRequest req, JacksonHelper jsonHelper,
        Class<T> requiredType) {
    Reader reader;
    try {
        reader = req.getContent().getReader();
        return jsonHelper.constructList(reader, requiredType);
    } catch (IOException e) {
        throw new ApiException("Could not read content from HTTP request body.", e.getCause());
    }
}

From source file:eu.learnpad.core.impl.dash.XwikiBridgeInterfaceRestResource.java

@Override
public String getKPIValuesView(String modelSetId, String businessActorId) throws LpRestException {

    HttpClient httpClient = this.getAnonymousClient();
    String uri = String.format("%s/learnpad/dash/bridge/view/%s", this.restPrefix, modelSetId);
    GetMethod getMethod = new GetMethod(uri);

    NameValuePair[] queryString = new NameValuePair[1];
    queryString[0] = new NameValuePair("businessactor", businessActorId);
    getMethod.setQueryString(queryString);

    try {//from   w ww .j  a  v  a2  s  . c  om
        httpClient.executeMethod(getMethod);
        return getMethod.getResponseBodyAsString();
    } catch (IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause());
    }
}

From source file:eu.learnpad.core.impl.qm.XwikiCoreFacadeRestResource.java

@Override
public void generationCompleted(String questionnairesId) throws LpRestException {
    // Now actually notifying the CP via REST
    HttpClient httpClient = this.getClient();
    String uri = String.format("%s/learnpad/qm/corefacade/generationcompleted/%s", DefaultRestResource.REST_URI,
            questionnairesId);/*from w  w  w .  ja va 2 s  .  c  om*/
    PutMethod putMethod = new PutMethod(uri);
    putMethod.addRequestHeader("Accept", MediaType.TEXT_PLAIN);
    try {
        httpClient.executeMethod(putMethod);
    } catch (IOException e) {
        LpRestExceptionXWikiImpl e1 = new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause());
        throw e1;
    }
}

From source file:org.apache.james.jmap.methods.RequestHandler.java

private Function<Method, Stream<JmapResponse>> extractAndProcess(AuthenticatedProtocolRequest request) {
    MailboxSession mailboxSession = request.getMailboxSession();
    return (Method method) -> {
        try {/*from w  w  w. j  a va2  s. c o m*/
            JmapRequest jmapRequest = jmapRequestParser.extractJmapRequest(request, method.requestType());
            return method.process(jmapRequest, request.getClientId(), mailboxSession);
        } catch (IOException e) {
            LOGGER.error("Error occured while parsing the request.", e);
            if (e.getCause() instanceof NotImplementedException) {
                return errorNotImplemented(request);
            }
            return error(request,
                    ErrorResponse.builder().type("invalidArguments").description(e.getMessage()).build());
        } catch (NotImplementedException e) {
            return errorNotImplemented(request);
        }
    };
}

From source file:com.ning.metrics.eventtracker.TestInvalidPayload.java

@Test(groups = "fast")
public void testWriteBadSmile() throws Exception {
    Assert.assertNull(listBinFiles(spoolDir));
    final DiskSpoolEventWriter writer = new DiskSpoolEventWriter(new TestEventHandler(), spoolPath, true, 1,
            executor, SyncType.NONE, 1, new NoCompressionCodec(), new SmileEnvelopeEventSerializer(false));

    try {//w  w  w  . j  a v  a 2s .c o  m
        writer.write(makeFailingEvent());
        Assert.fail();
    } catch (IOException e) {
        Assert.assertEquals(e.getCause().getClass(), JsonMappingException.class);
        // No file is currently being written (since the file was just moved aside)
        Assert.assertEquals(listBinFiles(tmpDir).length, 0);
        Assert.assertEquals(listBinFiles(spoolDir).length, 1);
    }

    writer.write(makeValidEvent());
    // One file being written (containing the valid event)
    Assert.assertEquals(listBinFiles(tmpDir).length, 1);
    // One file set aside (containing the invalid stream)
    Assert.assertEquals(listBinFiles(spoolDir).length, 1);

    // Make sure it still works
    writer.write(makeValidEvent());
    // One file being written (containing the valid event)
    Assert.assertEquals(listBinFiles(tmpDir).length, 1);
    // One file set aside (containing the invalid stream)
    Assert.assertEquals(listBinFiles(spoolDir).length, 1);
}