Java 类org.apache.commons.io.IOExceptionWithCause 实例源码

项目:data-prep    文件:LightweightExportableDataSetUtils.java   
/**
 * Reads token of the specified JsonParser and returns a list of column metadata.
 *
 * @param jsonParser the jsonParser whose next tokens are supposed to represent a list of column metadata
 * @return The column metadata parsed from JSON parser.
 * @throws IOException In case of JSON exception related error.
 */
private static List<ColumnMetadata> parseAnArrayOfColumnMetadata(JsonParser jsonParser) throws IOException {
    try {
        List<ColumnMetadata> columns = new ArrayList<>();
        // skip the array beginning [
        jsonParser.nextToken();
        while (jsonParser.nextToken() != JsonToken.END_ARRAY && !jsonParser.isClosed()) {
            ColumnMetadata columnMetadata = jsonParser.readValueAs(ColumnMetadata.class);
            columns.add(columnMetadata);
        }
        if (columns.isEmpty()) {
            throw new IllegalArgumentException(
                    "No column metadata has been retrieved when trying to parse the retrieved data set.");
        }
        return columns;
    } catch (IOException e) {
        throw new IOExceptionWithCause("Unable to parse and retrieve the list of column metadata", e);
    }
}
项目:data-prep    文件:LightweightExportableDataSetUtils.java   
private static RowMetadata parseDataSetMetadataAndReturnRowMetadata(JsonParser jsonParser) throws IOException {
    try {
        RowMetadata rowMetadata = null;
        while (jsonParser.nextToken() != JsonToken.END_OBJECT && !jsonParser.isClosed()) {
            String currentField = jsonParser.getCurrentName();
            if (StringUtils.equalsIgnoreCase("columns", currentField)) {
                rowMetadata = new RowMetadata(parseAnArrayOfColumnMetadata(jsonParser));
            }
        }
        LOGGER.debug("Skipping data to go back to the outer json object");
        while (jsonParser.getParsingContext().getParent().getCurrentName() != null && !jsonParser.isClosed()) {
            jsonParser.nextToken();
        }
        return rowMetadata;
    } catch (IOException e) {
        throw new IOExceptionWithCause("Unable to parse and retrieve the row metadata", e);
    }
}
项目:data-prep    文件:LightweightExportableDataSetUtils.java   
private static LightweightExportableDataSet parseRecords(JsonParser jsonParser, RowMetadata rowMetadata, String joinOnColumn)
        throws IOException {
    try {
        LightweightExportableDataSet lookupDataset = new LightweightExportableDataSet();
        lookupDataset.setMetadata(rowMetadata);
        jsonParser.nextToken();
        while (jsonParser.nextToken() != JsonToken.END_ARRAY && !jsonParser.isClosed()) {
            Map<String, String> values = jsonParser.readValueAs(Map.class);
            lookupDataset.addRecord(values.get(joinOnColumn), values);
        }
        if (lookupDataset.isEmpty()) {
            throw new IllegalArgumentException(
                    "No lookup record has been retrieved when trying to parse the retrieved data set.");
        }
        return lookupDataset;
    } catch (IOException e) {
        throw new IOExceptionWithCause("Unable to parse and retrieve the records of the data set", e);
    }
}
项目:pmcms    文件:ContentSaverServlet.java   
@Override
protected void doRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    Map<String, String> params = new HashMap<String, String>();
    Enumeration<?> paramNames = req.getParameterNames();
    while (paramNames.hasMoreElements()) {
        Object paramName = paramNames.nextElement();
        String name = Utils.stripNonValidXMLCharacters(paramName.toString());
        String value = Utils.stripNonValidXMLCharacters(req.getParameter(name));
        params.put(name, value);
    }
    APoormansObject<?> po = ContextUtil.updatepo(params);
    logger.info("Saved pojo: " + po.toString());

    try {
        if (InstanceUtil.isSiteResource(po))
            velocityRenderer.render(resp.getWriter(), (ASiteResource) po);
        else
            velocityRenderer.render(resp.getWriter(), (IRenderable) po, ViewMode.PREVIEW);
    } catch (RenderingException e) {
        throw new IOExceptionWithCause(e);
    }

    resp.setHeader("Cache-Control", "no-cache");
}
项目:opennmszh    文件:VmwareRequisitionUrlConnection.java   
/**
 * {@inheritDoc}
 * <p/>
 * Creates a ByteArrayInputStream implementation of InputStream of the XML
 * marshaled version of the Requisition class. Calling close on this stream
 * is safe.
 */
@Override
public InputStream getInputStream() throws IOException {

    InputStream stream = null;

    try {
        logger.debug("Getting existing requisition (if any) for VMware management server {}", m_hostname);
        Requisition curReq = getExistingRequisition();
        logger.debug("Building new requisition for VMware management server {}", m_hostname);
        Requisition newReq = buildVMwareRequisition();
        logger.debug("Finished building new requisition for VMware management server {}", m_hostname);
        if (curReq == null) {
            if (newReq == null) {
                // FIXME Is this correct ? This is the old behavior
                newReq = new Requisition(m_foreignSource);
            }
        } else {
            if (newReq == null) {
                // If there is a requisition and the vCenter is not responding for some reason, it is better to use the old requisition,
                // instead of returning an empty one, which can cause the lost of all the nodes from the DB.
                newReq = curReq;
            } else {
                // If there is already a requisition, retrieve the custom assets and categories from the old one, and put them on the new one.
                // The VMWare related assets and categories will be preserved.
                for (RequisitionNode newNode : newReq.getNodes()) {
                    for (RequisitionNode curNode : curReq.getNodes()) {
                        if (newNode.getForeignId().equals(curNode.getForeignId())) {
                            // Add existing custom assets
                            for (RequisitionAsset asset : curNode.getAssets()) {
                                if (!asset.getName().startsWith("vmware")) {
                                    newNode.putAsset(asset);
                                }
                            }
                            // Add existing custom categories
                            for (RequisitionCategory cat : curNode.getCategories()) {
                                if (!cat.getName().startsWith("VMWare")) {
                                    newNode.putCategory(cat);
                                }
                            }
                            // Add existing custom services
                            /*
                             * For each interface on the new requisition,
                             * - Retrieve the list of custom services from the corresponding interface on the existing requisition,
                             *   matching the interface by the IP address
                             * - If the list of services is not empty, add them to the new interface
                             */
                            for (RequisitionInterface intf : curNode.getInterfaces()) {
                                List<RequisitionMonitoredService> services = getManualyConfiguredServices(intf);
                                if (!services.isEmpty()) {
                                    RequisitionInterface newIntf = getRequisitionInterface(newNode, intf.getIpAddr());
                                    if (newIntf != null) {
                                        newIntf.getMonitoredServices().addAll(services);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        stream = new ByteArrayInputStream(jaxBMarshal(newReq).getBytes());
    } catch (Throwable e) {
        logger.warn("Problem getting input stream: '{}'", e);
        throw new IOExceptionWithCause("Problem getting input stream: " + e, e);
    }

    return stream;
}