Example usage for java.io IOException getClass

List of usage examples for java.io IOException getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.liferay.ci.portlet.JenkinsIntegrationPortlet.java

protected void buildProjectsStack(RenderRequest request) {
    PortletPreferences portletPreferences = request.getPreferences();

    String jobNamesParam = portletPreferences.getValue("jobnames", StringPool.BLANK);

    String[] jobNames = StringUtil.split(jobNamesParam, StringPool.NEW_LINE);

    AuthConnectionParams connectionParams = getConnectionParams(portletPreferences);

    try {//from w  w w  .  j  a  va 2s .  c o  m
        JenkinsJob[] lastBuilds = JenkinsConnectUtil.getLastBuilds(connectionParams, jobNames);

        request.setAttribute("JENKINS_JOBS", lastBuilds);
    } catch (IOException ioe) {
        SessionErrors.add(request, ioe.getClass());

        _log.error("The jobs were not available", ioe);
    } catch (JSONException e) {
        _log.error("The jobs are not well-formed", e);
    }
}

From source file:eu.project.ttc.engines.exporter.JsonCasExporter.java

@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
    /*/*from w  w  w . j  av a 2 s.  c o m*/
     *  Cette mthode est appele par le framework UIMA
     *  pour chaque document  de ta collection (corpus).
     *
     *  Tu peux gnrer ton fichier compagnon dans cette mthode.
     *  (Je te donne l'astuce pour retrouver le nom et le chemin du fichier
     *  de ton corpus correspondant au CAS pass en paramtre de cette
     *  mthode plus tard)
     */

    FSIterator<Annotation> it = aJCas.getAnnotationIndex().iterator();
    Annotation a;
    JsonFactory jsonFactory = new JsonFactory();
    String name = this.getExportFilePath(aJCas, "json");
    File file = new File(this.directoryFile, name);
    FileWriter writer = null;
    try {
        writer = new FileWriter(file);
        LOGGER.debug("Writing " + file.getPath());
        JsonGenerator jg = jsonFactory.createGenerator(writer);
        jg.useDefaultPrettyPrinter();
        jg.writeStartObject();
        jg.writeStringField("file", name);
        jg.writeArrayFieldStart("tag");
        while (it.hasNext()) {
            a = it.next();
            if (a instanceof WordAnnotation) {
                jg.writeStartObject();
                WordAnnotation wordAnno = (WordAnnotation) a;
                for (Feature feat : wordAnno.getType().getFeatures()) {
                    FeatureStructure featureValue = wordAnno.getFeatureValue(feat);
                    if (featureValue != null) {
                        jg.writeFieldName(feat.getName());
                        jg.writeObject(featureValue);
                    }
                }
                jg.writeStringField("tag", wordAnno.getTag());
                jg.writeStringField("lemma", wordAnno.getLemma());
                jg.writeNumberField("begin", wordAnno.getBegin());
                jg.writeNumberField("end", wordAnno.getEnd());
                jg.writeEndObject();
            }
        }
        jg.writeEndArray();
        jg.writeEndObject();
        jg.flush();
        writer.close();
    } catch (IOException e) {
        LOGGER.error("Failure while serializing " + name + "\nCaused by" + e.getClass().getCanonicalName() + ":"
                + e.getMessage(), e);
    }
}

From source file:com.liferay.ci.portlet.TravisIntegrationPortlet.java

protected void buildLights(RenderRequest request) {
    PortletPreferences portletPreferences = request.getPreferences();

    String account = portletPreferences.getValue("account", StringPool.BLANK);

    String jobName = portletPreferences.getValue("jobname", StringPool.BLANK);

    _log.debug("Getting builds for " + jobName);

    AuthConnectionParams connectionParams = getConnectionParams();

    try {//from  w w w .java2  s .c  om
        ContinuousIntegrationBuild lastBuild = JSONBuildUtil.getLastBuild(connectionParams, account, jobName);

        request.setAttribute(TravisIntegrationConstants.LAST_BUILD_STATUS, lastBuild.getStatus());

        if (lastBuild.getStatus() == TravisIntegrationConstants.TRAVIS_BUILD_STATUS_FAILED) {

            // retrieve number of broken tests for last build

            request.setAttribute("TEST_RESULTS", lastBuild);
        }
    } catch (IOException ioe) {
        SessionErrors.add(request, ioe.getClass());

        _log.error("The job was not available", ioe);
    } catch (JSONException e) {
        _log.error("The job is not well-formed", e);
    }
}

From source file:fr.gael.dhus.sync.smart.download.ProductDownloadTask.java

/**
 * Performs a download range (with multiple attempts if necessary) and
 * transfers downloaded bytes in the given channel.
 *
 * @param output output channel/*  w ww. j a v a  2s .c om*/
 * @return the number of bytes transferred
 * @throws IOException          if a I/O error occurred
 * @throws InterruptedException if the download is interrupted
 */
private long downloadRange(Pipe.SinkChannel output) throws IOException, InterruptedException {
    long start = skip;
    CountingIWC counter = new CountingIWC<>(output);

    for (int time = 1; (skip + counter.currentCount()) < contentLength && time < attempts; time++) {
        try {
            httpClient.interruptibleGetRange(url, counter, eTag, start, contentLength);
        } catch (IOException e) {
            LOGGER.debug("Download of {} interrupted cause by {}:{}", url, e.getClass(), e.getMessage());
            start = skip + counter.currentCount();
        }
    }

    return counter.currentCount();
}

From source file:com.liferay.ci.portlet.JenkinsIntegrationPortlet.java

protected void buildLights(RenderRequest request) {
    PortletPreferences portletPreferences = request.getPreferences();

    String jobName = portletPreferences.getValue("jobname", StringPool.BLANK);

    _log.debug("Getting builds for " + jobName);

    AuthConnectionParams connectionParams = getConnectionParams(portletPreferences);

    try {/*from w  w w  .j  ava 2 s .c o m*/
        JenkinsBuild lastBuild = JenkinsConnectUtil.getLastBuild(connectionParams, jobName);

        request.setAttribute("LAST_BUILD_STATUS", lastBuild.getStatus());

        if (lastBuild.getStatus().equals(JenkinsIntegrationConstants.JENKINS_BUILD_STATUS_UNSTABLE)) {

            // retrieve number of broken tests for last build

            request.setAttribute("TEST_RESULTS", lastBuild);
        }
    } catch (IOException ioe) {
        SessionErrors.add(request, ioe.getClass());

        _log.error("The job was not available", ioe);
    } catch (JSONException e) {
        _log.error("The job is not well-formed", e);
    }
}

From source file:com.twinsoft.convertigo.engine.admin.services.mobiles.GetPackage.java

@Override
protected void writeResponseResult(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String project = Keys.project.value(request);

    MobileApplication mobileApplication = GetBuildStatus.getMobileApplication(project);

    if (mobileApplication == null) {
        throw new ServiceException("no such mobile application");
    } else {//from  w  w  w  . j a v  a 2 s .  com
        boolean bAdminRole = Engine.authenticatedSessionManager.hasRole(request.getSession(), Role.WEB_ADMIN);
        if (!bAdminRole && mobileApplication.getAccessibility() == Accessibility.Private) {
            throw new AuthenticationException("Authentication failure: user has not sufficient rights!");
        }
    }

    String platformName = Keys.platform.value(request);
    String finalApplicationName = mobileApplication.getComputedApplicationName();

    String mobileBuilderPlatformURL = EnginePropertiesManager
            .getProperty(PropertyName.MOBILE_BUILDER_PLATFORM_URL);

    PostMethod method;
    int methodStatusCode;
    InputStream methodBodyContentInputStream;

    URL url = new URL(mobileBuilderPlatformURL + "/getpackage");

    HostConfiguration hostConfiguration = new HostConfiguration();
    hostConfiguration.setHost(new URI(url.toString(), true));
    HttpState httpState = new HttpState();
    Engine.theApp.proxyManager.setProxy(hostConfiguration, httpState, url);

    method = new PostMethod(url.toString());

    try {
        HeaderName.ContentType.setRequestHeader(method, MimeType.WwwForm.value());
        method.setRequestBody(new NameValuePair[] { new NameValuePair("application", finalApplicationName),
                new NameValuePair("platformName", platformName),
                new NameValuePair("auth_token", mobileApplication.getComputedAuthenticationToken()),
                new NameValuePair("endpoint", mobileApplication.getComputedEndpoint(request)) });

        methodStatusCode = Engine.theApp.httpClient.executeMethod(hostConfiguration, method, httpState);
        methodBodyContentInputStream = method.getResponseBodyAsStream();

        if (methodStatusCode != HttpStatus.SC_OK) {
            byte[] httpBytes = IOUtils.toByteArray(methodBodyContentInputStream);
            String sResult = new String(httpBytes, "UTF-8");
            throw new ServiceException("Unable to get package for project '" + project + "' (final app name: '"
                    + finalApplicationName + "').\n" + sResult);
        }

        try {
            String contentDisposition = method.getResponseHeader(HeaderName.ContentDisposition.value())
                    .getValue();
            HeaderName.ContentDisposition.setHeader(response, contentDisposition);
        } catch (Exception e) {
            HeaderName.ContentDisposition.setHeader(response, "attachment; filename=\"" + project + "\"");
        }

        try {
            response.setContentType(method.getResponseHeader(HeaderName.ContentType.value()).getValue());
        } catch (Exception e) {
            response.setContentType(MimeType.OctetStream.value());
        }

        OutputStream responseOutputStream = response.getOutputStream();
        IOUtils.copy(methodBodyContentInputStream, responseOutputStream);
    } catch (IOException ioex) { // Fix for ticket #4698
        if (!ioex.getClass().getSimpleName().equalsIgnoreCase("ClientAbortException")) {
            // fix for #5042
            throw ioex;
        }
    } finally {
        method.releaseConnection();
    }
}

From source file:org.sakaiproject.archive.impl.ArchiveService2Impl.java

@Override
public String mergeFromZip(String zipFilePath, String siteId, String creatorId) {
    try {//from  w w  w.  ja v a2  s  .  co m
        String fileName = m_siteZipper.unzipArchive(zipFilePath, m_unzipPath);
        //not a lot we can do with the return value here since it always returns a string. would need a reimplementation/wrapper method to return a better value (boolean or some status)
        return m_siteMerger.merge(fileName, siteId, creatorId, m_storagePath, m_filterSakaiServices,
                m_filteredSakaiServices, m_filterSakaiRoles, m_filteredSakaiRoles);
    } catch (IOException e) {
        M_log.error("Error merging from zip: " + e.getClass() + ":" + e.getMessage());
        return "Error merging from zip: " + e.getClass() + ":" + e.getMessage();
    }
}

From source file:com.github.horrorho.inflatabledonkey.cloud.Donkey.java

void fetchContainer(HttpClient httpClient, StorageHostChunkList container) {
    ChunkServer.HostInfo hostInfo = container.getHostInfo();
    logger.trace("<< fetchContainer() - uri: {}", hostInfo.getHostname() + "/" + hostInfo.getUri());

    if (logger.isDebugEnabled()) {
        int size = container.getChunkInfoList().stream().mapToInt(ChunkInfo::getChunkLength).sum();
        logger.debug("-- fetchContainer() - chunks: {} size: {}", container.getChunkInfoCount(), size);
    }/*  w w w.  j a va 2  s.c  o m*/

    try {
        chunkClient.apply(httpClient, container, store);
    } catch (IOException ex) {
        logger.warn("-- fetchContainer() - {} {}", ex.getClass().getCanonicalName(), ex.getMessage());
    } catch (IllegalArgumentException ex) {
        // Shouldn't happen unless we pass non type 0x01 keys.
        logger.warn("-- fetchContainer() - internal error: {}", ex.getMessage());
    }

    logger.trace(">> fetchContainer()");
}

From source file:org.dataconservancy.ui.api.BaseController.java

@ExceptionHandler(IOException.class)
public void handleException(IOException e, HttpServletRequest req, HttpServletResponse resp) {
    log.debug("Handling exception [" + e.getClass() + "] [" + e.getMessage() + "]");
    resp.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);

    try {/*from w ww .j  a  v  a2 s. c  o m*/
        resp.getWriter().print(e.getMessage());
        resp.getWriter().flush();
        resp.getWriter().close();
    } catch (Exception ee) {
        log.debug("Handling exception", e);
    }
}

From source file:com.discovery.darchrow.http.ResponseUtil.java

/**
 * Down load data.//ww w. j  a v  a  2s .  c om
 *
 * @param saveFileName
 *            the save file name
 * @param inputStream
 *            the input stream
 * @param contentLength
 *            the content length
 * @param request
 *            the request
 * @param response
 *            the response
 * @throws UncheckedIOException
 *             the unchecked io exception
 */
private static void downLoadData(String saveFileName, InputStream inputStream, Number contentLength,
        HttpServletRequest request, HttpServletResponse response) throws UncheckedIOException {
    Date beginDate = new Date();

    if (log.isInfoEnabled()) {
        log.info("begin download~~,saveFileName:[{}],contentLength:[{}]", saveFileName,
                FileUtil.formatSize(contentLength.longValue()));
    }
    try {
        OutputStream outputStream = response.getOutputStream();

        //? 
        //inputStream.read(buffer);
        //outputStream = new BufferedOutputStream(response.getOutputStream());
        //outputStream.write(buffer);

        IOWriteUtil.write(inputStream, outputStream);
        if (log.isInfoEnabled()) {
            Date endDate = new Date();
            log.info("end download,saveFileName:[{}],contentLength:[{}],time use:[{}]", saveFileName,
                    FileUtil.formatSize(contentLength.longValue()),
                    DateExtensionUtil.getIntervalForView(beginDate, endDate));
        }
    } catch (IOException e) {
        /*
         * ?  ClientAbortException  ????? 
         * ?? ??
         * ???????
         * ? KILL? ?? ClientAbortException
         */
        //ClientAbortException:  java.net.SocketException: Connection reset by peer: socket write error
        final String exceptionName = e.getClass().getName();

        if (StringUtil.isContain(exceptionName, "ClientAbortException")
                || StringUtil.isContain(e.getMessage(), "ClientAbortException")) {
            log.warn(
                    "[ClientAbortException],maybe user use Thunder soft or abort client soft download,exceptionName:[{}],exception message:[{}] ,request User-Agent:[{}]",
                    exceptionName, e.getMessage(), RequestUtil.getHeaderUserAgent(request));
        } else {
            log.error("[download exception],exception name: " + exceptionName, e);
            throw new UncheckedIOException(e);
        }
    }
}