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:com.jivesoftware.os.amza.service.replication.http.endpoints.AmzaReplicationRestEndpoints.java

@POST
@Consumes(MediaType.APPLICATION_JSON)/*from  ww w.  j  a  v a  2  s .co m*/
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Path("/rows/stream/{ringMemberString}/{versionedPartitionName}/{takeSessionId}/{txId}/{leadershipToken}/{limit}")
public Response rowsStream(@PathParam("ringMemberString") String ringMemberString,
        @PathParam("versionedPartitionName") String versionedPartitionName,
        @PathParam("takeSessionId") long takeSessionId, @PathParam("txId") long txId,
        @PathParam("leadershipToken") long leadershipToken, @PathParam("limit") long limit,
        byte[] takeSharedKey) {

    try {
        amzaStats.rowsStream.increment();

        StreamingOutput stream = (OutputStream os) -> {
            os.flush();
            BufferedOutputStream bos = new BufferedOutputStream(new SnappyOutputStream(os), 8192); // TODO expose to config
            final DataOutputStream dos = new DataOutputStream(bos);
            try {
                amzaInstance.rowsStream(dos, new RingMember(ringMemberString),
                        VersionedPartitionName.fromBase64(versionedPartitionName, amzaInterner), takeSessionId,
                        objectMapper.readValue(takeSharedKey, Long.class), txId, leadershipToken, limit);
            } catch (IOException x) {
                if (x.getCause() instanceof TimeoutException) {
                    LOG.error("Timed out while streaming takes");
                } else {
                    LOG.error("Failed to stream takes.", x);
                }
                throw x;
            } catch (Exception x) {
                LOG.error("Failed to stream takes.", x);
                throw new IOException("Failed to stream takes.", x);
            } finally {
                dos.flush();
                amzaStats.rowsStream.decrement();
                amzaStats.completedRowsStream.increment();
            }
        };
        return Response.ok(stream).build();
    } catch (Exception x) {
        Object[] vals = new Object[] { ringMemberString, versionedPartitionName, txId };
        LOG.warn("Failed to rowsStream {} {} {}. ", vals, x);
        return ResponseHelper.INSTANCE.errorResponse("Failed to rowsStream " + Arrays.toString(vals), x);
    }
}

From source file:org.apache.flink.yarn.cli.FlinkYarnCLI.java

@Override
public YarnClusterClientV2 createCluster(String applicationName, CommandLine cmdLine, Configuration config,
        List<URL> userJarFiles) {
    Preconditions.checkNotNull(userJarFiles, "User jar files should not be null.");

    YarnClusterDescriptorV2 yarnClusterDescriptor = createDescriptor(applicationName, cmdLine);
    yarnClusterDescriptor.setFlinkConfiguration(config);
    yarnClusterDescriptor.setProvidedUserJarFiles(userJarFiles);

    YarnClusterClientV2 client = null;//from ww w .j a  v  a 2s.  c  o  m
    try {
        client = new YarnClusterClientV2(yarnClusterDescriptor, config);
    } catch (IOException e) {
        throw new RuntimeException("Fail to create YarnClusterClientV2", e.getCause());
    }
    return client;

}

From source file:org.onehippo.repository.xml.SysViewSAXEventGenerator.java

private void exportValue(final Value val) throws RepositoryException, SAXException {

    if (val.getType() == BINARY && binaries != null) {
        File file = createBinaryFile(val);
        binaries.add(file);/*  w w  w  .  ja v a2s. c  o m*/
        AttributesImpl attributes = new AttributesImpl();
        attributes.addAttribute(NS_XMLIMPORT_URI, "file", "h:file", CDATA_TYPE, file.getName());
        contentHandler.startPrefixMapping(NS_XMLIMPORT_PREFIX, NS_XMLIMPORT_URI);
        startElement(SV_VALUE, attributes);
        endElement(SV_VALUE);
        contentHandler.endPrefixMapping(NS_XMLIMPORT_PREFIX);
    } else {
        Attributes attributes = ATTRS_EMPTY;
        final boolean mustSendBinary = mustSendBinary(val);
        if (mustSendBinary) {
            contentHandler.startPrefixMapping(NS_XMLSCHEMA_INSTANCE_PREFIX, NS_XMLSCHEMA_INSTANCE_URI);
            contentHandler.startPrefixMapping(NS_XMLSCHEMA_PREFIX, NS_XMLSCHEMA_URI);
            attributes = ATTRS_BINARY_ENCODED_VALUE;
        }
        startElement(SV_VALUE, attributes);

        try {
            ValueHelper.serialize(val, false, mustSendBinary, new ContentHandlerWriter(contentHandler));
        } catch (IOException ioe) {
            Throwable t = ioe.getCause();
            if (t != null && t instanceof SAXException) {
                throw (SAXException) t;
            } else {
                throw new SAXException(ioe);
            }
        }

        endElement(SV_VALUE);

        if (mustSendBinary) {
            contentHandler.endPrefixMapping(NS_XMLSCHEMA_INSTANCE_PREFIX);
            contentHandler.endPrefixMapping(NS_XMLSCHEMA_PREFIX);
        }
    }

}

From source file:no.uio.ifi.models.search.GeolocationSearch.java

/**
 * Initialize a YouTube object to search for videos on YouTube. Then
 * display the name and thumbnail image of each video in the result set.
 *
 * @param args command line args./*from  www .  j  ava  2 s.  c  o m*/
 */

public List<Video> searchVideoBaseOnLocation(String keyword, String city, String distance) {
    // Read the developer key from the properties file.
    List<Video> videoList = null;
    Properties properties = new Properties();
    try {
        InputStream in = GeolocationSearch.class.getResourceAsStream("/" + PROPERTIES_FILENAME);
        properties.load(in);

    } catch (IOException e) {
        System.err.println("There was an error reading " + PROPERTIES_FILENAME + ": " + e.getCause() + " : "
                + e.getMessage());
        System.exit(1);
    }

    try {
        // This object is used to make YouTube Data API requests. The last
        // argument is required, but since we don't need anything
        // initialized when the HttpRequest is initialized, we override
        // the interface and provide a no-op function.
        youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, new HttpRequestInitializer() {
            @Override
            public void initialize(HttpRequest request) throws IOException {
            }
        }).setApplicationName("youtube-cmdline-geolocationsearch-sample").build();

        // Define the API request for retrieving search results.
        YouTube.Search.List search = youtube.search().list("id,snippet");

        // Set your developer key from the Google Developers Console for
        // non-authenticated requests. See:
        // https://console.developers.google.com/
        String apiKey = properties.getProperty("youtube.apikey");
        search.setKey(apiKey);
        search.setQ(keyword);

        FindGPSOnName locationGPS = new FindGPSOnName();
        String location = locationGPS.getGeolocationCity(city);

        search.setLocation(location);
        search.setLocationRadius(distance);

        // Restrict the search results to only include videos. See:
        // https://developers.google.com/youtube/v3/docs/search/list#type
        search.setType("video");

        // As a best practice, only retrieve the fields that the
        // application uses.
        search.setFields("items(id/videoId)");
        search.setMaxResults(NUMBER_OF_VIDEOS_RETURNED);

        // Call the API
        SearchListResponse searchResponse = search.execute();
        List<SearchResult> searchResultList = searchResponse.getItems();
        List<String> videoIds = new ArrayList<String>();

        if (searchResultList != null) {

            // Merge video IDs
            for (SearchResult searchResult : searchResultList) {
                videoIds.add(searchResult.getId().getVideoId());
            }
            Joiner stringJoiner = Joiner.on(',');
            String videoId = stringJoiner.join(videoIds);

            // Call the YouTube Data API's youtube.videos.list method to
            // retrieve the resources that represent the specified videos.
            YouTube.Videos.List listVideosRequest = youtube.videos().list("snippet, recordingDetails")
                    .setId(videoId);

            // Set your developer key
            listVideosRequest.setKey(apiKey);

            VideoListResponse listResponse = listVideosRequest.execute();
            videoList = listResponse.getItems();
        }
    } catch (GoogleJsonResponseException e) {
        System.err.println(
                "There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
    } catch (IOException e) {
        System.err.println("There was an IO error: " + e.getCause() + " : " + e.getMessage());
    } catch (Throwable t) {
        t.printStackTrace();
    }

    return videoList;
}

From source file:com.taobao.datax.plugins.reader.oraclereader.OracleReader.java

@Override
public int prepare(PluginParam param) {
    if (!StringUtils.isBlank(this.ip) && !StringUtils.isBlank(this.port)) {
        /* User defined ip & port */
        this.connectKey = DBSource.genKey(this.getClass(), this.ip, this.port, this.dbname);
        DBSource.register(this.connectKey, this.createProperties());
        this.connection = DBSource.getConnection(this.connectKey);
    } else {//w  w w  .  j  a v  a 2 s .c  o  m
        /* Non-user defined ip & port */
        List<Map<String, String>> details;
        try {
            details = OracleTnsAssist.newInstance(tnsname).search(dbname);
        } catch (IOException e1) {
            throw new DataExchangeException(e1.getCause());
        }

        /* try every connect info */
        for (Map<String, String> kv : details) {
            this.ip = kv.get(OracleTnsAssist.HOST_KEY);
            this.port = kv.get(OracleTnsAssist.PORT_KEY);
            this.dbname = kv.get(OracleTnsAssist.SID_KEY);
            this.connectKey = DBSource.genKey(this.getClass(), ip, port, dbname);
            try {
                DBSource.register(this.connectKey, this.createProperties());
                this.connection = DBSource.getConnection(this.connectKey);
            } catch (Exception e) {
                logger.error(String.format("OracleReader try to connect %s:%s failed ", this.ip, this.port));
                continue;
            }
            if (null != this.connection) {
                break;
            }
        }
    }

    if (null == this.connection) {
        String msg = "OracleReader try to connect to database failed .";
        logger.error(msg);
        throw new DataExchangeException(msg);
    }

    param.putValue(ORACLE_READER_DB_POOL_KEY, this.connectKey);
    return PluginStatus.SUCCESS.value();
}

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

@Override
public String joinProcessInstance(String simulationId, String userId) throws LpRestException {
    HttpClient httpClient = this.getAnonymousClient();
    String uri = String.format("%s/learnpad/sim/bridge/instances/%s/%s", this.restPrefix, simulationId, userId);

    GetMethod getMethod = new GetMethod(uri);

    try {//from w  w w  .j  a  va  2s .c  o m
        httpClient.executeMethod(getMethod);
        return IOUtils.toString(getMethod.getResponseBodyAsStream());
    } catch (IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause());
    }
}

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

@Override
public Collection<String> getProcessDefinitions() throws LpRestException {
    HttpClient httpClient = this.getAnonymousClient();
    String uri = String.format("%s/learnpad/sim/bridge/processes", this.restPrefix);

    GetMethod getMethod = new GetMethod(uri);
    getMethod.addRequestHeader("Content-Type", "application/json");

    try {/*from   w w w.j a v a2  s  .com*/

        httpClient.executeMethod(getMethod);

        // Not fully tested, but is looks working for our purposes -- Gulyx
        return this.objectReaderCollection.readValue(getMethod.getResponseBodyAsStream());
    } catch (IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause());
    }
}

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

@Override
public ProcessData getProcessInfos(String processArtifactId) throws LpRestException {
    HttpClient httpClient = this.getAnonymousClient();
    String uri = String.format("%s/learnpad/sim/bridge/processes/%s", this.restPrefix, processArtifactId);

    GetMethod getMethod = new GetMethod(uri);
    getMethod.addRequestHeader("Content-Type", "application/json");

    try {/*  w w  w  .  j  a  v  a  2s. c o  m*/

        httpClient.executeMethod(getMethod);

        // Not fully tested, but is looks working for our purposes -- Gulyx
        return objectReaderProcessData.readValue(getMethod.getResponseBodyAsStream());
    } catch (IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause());
    }
}

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

@Override
public Collection<String> getProcessInstances() throws LpRestException {
    HttpClient httpClient = this.getAnonymousClient();
    String uri = String.format("%s/learnpad/sim/bridge/instances", this.restPrefix);

    GetMethod getMethod = new GetMethod(uri);
    getMethod.addRequestHeader("Content-Type", "application/json");

    try {//from w  ww. j  a  va 2  s  .c  om

        httpClient.executeMethod(getMethod);

        // Not fully tested, but is looks working for our purposes -- Gulyx
        return objectReaderCollection.readValue(getMethod.getResponseBodyAsStream());
    } catch (IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause());
    }
}

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

@Override
public ProcessInstanceData getProcessInstanceInfos(String processInstanceArtifactId) throws LpRestException {
    HttpClient httpClient = this.getAnonymousClient();
    String uri = String.format("%s/learnpad/sim/bridge/instances/%s", this.restPrefix,
            processInstanceArtifactId);//from w  ww. java2s  .  c om

    GetMethod getMethod = new GetMethod(uri);
    getMethod.addRequestHeader("Content-Type", "application/json");

    try {

        httpClient.executeMethod(getMethod);

        // Not fully tested, but is looks working for our purposes -- Gulyx
        return objectReaderProcessInstanceData.readValue(getMethod.getResponseBodyAsStream());
    } catch (IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause());
    }
}