Example usage for java.io Writer toString

List of usage examples for java.io Writer toString

Introduction

In this page you can find the example usage for java.io Writer toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:ddf.security.pdp.realm.xacml.processor.BalanaClientTest.java

@Test
public void testBalanaWrapperpoliciesdirectorypolicyadded() throws Exception {
    LOGGER.debug("\n\n\n##### testBalanaWrapper_policies_directory_policy_added");

    File policyDir = folder.newFolder("tempDir");

    BalanaClient.defaultPollingIntervalInSeconds = 1;
    // Perform Test
    BalanaClient pdp = new BalanaClient(policyDir.getCanonicalPath(), new XmlParser());

    File srcFile = new File(
            projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE);
    FileUtils.copyFileToDirectory(srcFile, policyDir);

    Thread.sleep(2000);/*  w w  w  . j  a v  a 2s. c  o  m*/

    RequestType xacmlRequestType = new RequestType();
    xacmlRequestType.setCombinedDecision(false);
    xacmlRequestType.setReturnPolicyIdList(false);

    AttributesType actionAttributes = new AttributesType();
    actionAttributes.setCategory(ACTION_CATEGORY);
    AttributeType actionAttribute = new AttributeType();
    actionAttribute.setAttributeId(ACTION_ID);
    actionAttribute.setIncludeInResult(false);
    AttributeValueType actionValue = new AttributeValueType();
    actionValue.setDataType(STRING_DATA_TYPE);
    actionValue.getContent().add(QUERY_ACTION);
    actionAttribute.getAttributeValue().add(actionValue);
    actionAttributes.getAttribute().add(actionAttribute);

    AttributesType subjectAttributes = new AttributesType();
    subjectAttributes.setCategory(SUBJECT_CATEGORY);
    AttributeType subjectAttribute = new AttributeType();
    subjectAttribute.setAttributeId(SUBJECT_ID);
    subjectAttribute.setIncludeInResult(false);
    AttributeValueType subjectValue = new AttributeValueType();
    subjectValue.setDataType(STRING_DATA_TYPE);
    subjectValue.getContent().add(TEST_USER_1);
    subjectAttribute.getAttributeValue().add(subjectValue);
    subjectAttributes.getAttribute().add(subjectAttribute);

    AttributeType roleAttribute = new AttributeType();
    roleAttribute.setAttributeId(ROLE_CLAIM);
    roleAttribute.setIncludeInResult(false);
    AttributeValueType roleValue = new AttributeValueType();
    roleValue.setDataType(STRING_DATA_TYPE);
    roleValue.getContent().add(ROLE);
    roleAttribute.getAttributeValue().add(roleValue);
    subjectAttributes.getAttribute().add(roleAttribute);

    AttributesType categoryAttributes = new AttributesType();
    categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
    AttributeType citizenshipAttribute = new AttributeType();
    citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
    citizenshipAttribute.setIncludeInResult(false);
    AttributeValueType citizenshipValue = new AttributeValueType();
    citizenshipValue.setDataType(STRING_DATA_TYPE);
    citizenshipValue.getContent().add(US_COUNTRY);
    citizenshipAttribute.getAttributeValue().add(citizenshipValue);
    categoryAttributes.getAttribute().add(citizenshipAttribute);

    xacmlRequestType.getAttributes().add(actionAttributes);
    xacmlRequestType.getAttributes().add(subjectAttributes);
    xacmlRequestType.getAttributes().add(categoryAttributes);

    // Perform Test
    ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);

    // Verify - The policy was loaded to allow a permit decision
    JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    ObjectFactory objectFactory = new ObjectFactory();
    Writer writer = new StringWriter();
    marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer);
    LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString());
    assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.PERMIT);

    FileUtils.deleteDirectory(policyDir);
}

From source file:ddf.security.pdp.realm.xacml.processor.XacmlClientTest.java

@Test
public void testWrapperpoliciesdirectorypolicyadded() throws Exception {
    LOGGER.debug("\n\n\n##### testXACMLWrapper_policies_directory_policy_added");

    File policyDir = folder.newFolder("tempDir");

    XacmlClient.defaultPollingIntervalInSeconds = 1;
    // Perform Test
    XacmlClient pdp = new XacmlClient(policyDir.getCanonicalPath(), new XmlParser());

    File srcFile = new File(
            projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE);
    FileUtils.copyFileToDirectory(srcFile, policyDir);

    Thread.sleep(2000);//w w w .  j a  v a  2  s .  c om

    RequestType xacmlRequestType = new RequestType();
    xacmlRequestType.setCombinedDecision(false);
    xacmlRequestType.setReturnPolicyIdList(false);

    AttributesType actionAttributes = new AttributesType();
    actionAttributes.setCategory(ACTION_CATEGORY);
    AttributeType actionAttribute = new AttributeType();
    actionAttribute.setAttributeId(ACTION_ID);
    actionAttribute.setIncludeInResult(false);
    AttributeValueType actionValue = new AttributeValueType();
    actionValue.setDataType(STRING_DATA_TYPE);
    actionValue.getContent().add(QUERY_ACTION);
    actionAttribute.getAttributeValue().add(actionValue);
    actionAttributes.getAttribute().add(actionAttribute);

    AttributesType subjectAttributes = new AttributesType();
    subjectAttributes.setCategory(SUBJECT_CATEGORY);
    AttributeType subjectAttribute = new AttributeType();
    subjectAttribute.setAttributeId(SUBJECT_ID);
    subjectAttribute.setIncludeInResult(false);
    AttributeValueType subjectValue = new AttributeValueType();
    subjectValue.setDataType(STRING_DATA_TYPE);
    subjectValue.getContent().add(TEST_USER_1);
    subjectAttribute.getAttributeValue().add(subjectValue);
    subjectAttributes.getAttribute().add(subjectAttribute);

    AttributeType roleAttribute = new AttributeType();
    roleAttribute.setAttributeId(ROLE_CLAIM);
    roleAttribute.setIncludeInResult(false);
    AttributeValueType roleValue = new AttributeValueType();
    roleValue.setDataType(STRING_DATA_TYPE);
    roleValue.getContent().add(ROLE);
    roleAttribute.getAttributeValue().add(roleValue);
    subjectAttributes.getAttribute().add(roleAttribute);

    AttributesType categoryAttributes = new AttributesType();
    categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
    AttributeType citizenshipAttribute = new AttributeType();
    citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
    citizenshipAttribute.setIncludeInResult(false);
    AttributeValueType citizenshipValue = new AttributeValueType();
    citizenshipValue.setDataType(STRING_DATA_TYPE);
    citizenshipValue.getContent().add(US_COUNTRY);
    citizenshipAttribute.getAttributeValue().add(citizenshipValue);
    categoryAttributes.getAttribute().add(citizenshipAttribute);

    xacmlRequestType.getAttributes().add(actionAttributes);
    xacmlRequestType.getAttributes().add(subjectAttributes);
    xacmlRequestType.getAttributes().add(categoryAttributes);

    // Perform Test
    ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);

    // Verify - The policy was loaded to allow a permit decision
    JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    ObjectFactory objectFactory = new ObjectFactory();
    Writer writer = new StringWriter();
    marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer);
    LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString());
    assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.PERMIT);

    FileUtils.deleteDirectory(policyDir);
}

From source file:org.kalypso.simulation.core.ant.GMLWeightingOperation.java

public void execute() throws Exception {
    final IUrlResolver urlResolver = UrlResolverSingleton.getDefault();
    // create needed factories
    final Marshaller marshaller = JaxbUtilities.createMarshaller(ZmlFactory.JC, true);

    // workspace for results
    final URL modelURL = m_data.getModelLocation();
    final GMLWorkspace resultWorkspace = CopyObservationMappingHelper.createMappingWorkspace(modelURL);

    // 1. load srcgml
    m_logger.log(Level.INFO, -1, "Lade Modell " + modelURL);
    final GMLWorkspace workspace = GmlSerializer.createGMLWorkspace(modelURL, null);
    m_namespaceContext = workspace.getNamespaceContext();

    // 2. locate features to process
    final GMLXPath targetFeaturePath = asPath(m_data.getTargetFeaturePath());
    final Feature[] targetFeatures = resolveFeatures(workspace.getRootFeature(), targetFeaturePath);
    if (targetFeatures == null)
        throw new BuildException("Kein(e) Ziel-Feature(s) gefunden fr FeaturePath: " + targetFeaturePath);

    final GMLXPath targetZMLPath = asPath(m_data.getTargetZMLProperty());
    final URL targetContext = m_data.getTargetContext();

    final GMLXPath sourceMember = asPath(m_data.getSourceMember());

    final GMLXPath weightPath = asPath(m_data.getWeightProperty());
    final GMLXPath offsetPath = asPath(m_data.getOffsetProperty());

    // loop all features
    for (final Feature targetFE : targetFeatures) {
        // 3. find target
        final TimeseriesLinkType targetLink = GMLXPathUtilities.query(targetZMLPath, targetFE);
        final String targetHref = targetLink.getHref();
        final URL targetURL = urlResolver.resolveURL(targetContext, targetHref);

        // 4. build n-operation filter
        final NOperationFilterType nOperationFilter = FilterFactory.OF_FILTER.createNOperationFilterType();
        nOperationFilter.setOperator("+"); //$NON-NLS-1$
        final List<JAXBElement<? extends AbstractFilterType>> filterList = nOperationFilter.getFilter();

        // 5. resolve weights

        final GMLXPath weightMember = asPath(m_data.getWeightMember());
        final Feature[] weightFEs = resolveFeatures(targetFE, weightMember);
        if (weightFEs == null)
            throw new BuildException("Kein(e) Gewichts-Feature(s) gefunden fr FeaturePath: " + weightMember);

        // 6. loop weights
        for (final Feature weightFE : weightFEs) {
            final double factor = getFactor(weightFE, weightPath);
            final double offset = getOffset(weightFE, offsetPath);

            // 7. resolve sources
            final Feature[] sourceFeatures = resolveFeatures(weightFE, sourceMember);
            if (sourceFeatures == null)
                throw new BuildException("Kein(e) Quell-Feature(s) gefunden fr FeaturePath: " + sourceMember);

            final OperationFilterType offsetFilter = FilterFactory.OF_FILTER.createOperationFilterType();
            offsetFilter.setOperator("+"); //$NON-NLS-1$
            offsetFilter.setOperand(Double.toString(offset));

            final NOperationFilterType weightSumFilter = FilterFactory.OF_FILTER.createNOperationFilterType();
            weightSumFilter.setOperator("+"); //$NON-NLS-1$

            offsetFilter.setFilter(FilterFactory.OF_FILTER.createNOperationFilter(weightSumFilter));

            final List<JAXBElement<? extends AbstractFilterType>> offsetSummands = weightSumFilter.getFilter();

            addSourceSummands(weightFE, factor, sourceFeatures, offsetSummands);
            /* Empty NOperation filter is forbidden */
            // Bad warning message, can happen if all sub-elements are disabled
            if (offsetSummands.isEmpty()) {
                // m_logger.log( Level.WARNING, LoggerUtilities.CODE_SHOW_DETAILS, "Leere Summe fr Feature: " +
                // weightFE.getId() );
            } else
                filterList.add(FilterFactory.OF_FILTER.createOperationFilter(offsetFilter));
        }//from www . j  a v a2  s.  c  o  m

        /* Empty NOperation filter is forbidden */
        if (filterList.isEmpty()) {
            m_logger.log(Level.SEVERE, LoggerUtilities.CODE_SHOW_MSGBOX,
                    "Leere Summe fr Feature: " + targetFE.getId());
            return;
        }

        // 11. serialize filter to string
        final Writer writer = new StringWriter();
        marshaller.marshal(FilterFactory.OF_FILTER.createNOperationFilter(nOperationFilter), writer);
        writer.close();
        final String string = XMLUtilities.removeXMLHeader(writer.toString());
        final String filterInline = XMLUtilities.prepareInLine(string);

        // 12. add mapping to result workspace
        CopyObservationMappingHelper.addMapping(resultWorkspace, filterInline, targetURL.toExternalForm());
        m_logger.log(Level.INFO, -1, "Ziel-ZML " + targetURL);
    }

    // 14. do the mapping
    final Date sourceFrom = m_data.getSourceFrom();
    final Date sourceTo = m_data.getSourceTo();
    final Date targetFrom = m_data.getTargetFrom();
    final Date targetTo = m_data.getTargetTo();
    final Date forecastFrom = m_data.getForecastFrom();
    final Date forecastTo = m_data.getForecastTo();

    final DateRange measuredRange = DateRange.createDateRangeOrNull(sourceFrom, sourceTo);
    final DateRange keForecastRange = DateRange.createDateRangeOrNull(targetFrom, targetTo);
    final DateRange forecastMetadataRange = DateRange.createDateRangeOrNull(forecastFrom, forecastTo);

    CopyObservationMappingHelper.runMapping(resultWorkspace, modelURL, m_logger, true, measuredRange,
            keForecastRange, forecastMetadataRange);

    // 15. serialize result workspace to file
    final File targetMapping = m_data.getTargetMapping();
    if (targetMapping != null) {
        FileWriter writer = null;
        try {
            writer = new FileWriter(targetMapping);
            GmlSerializer.serializeWorkspace(writer, resultWorkspace);
            writer.close();
        } finally {
            IOUtils.closeQuietly(writer);
        }
    }
}

From source file:com.glaf.dts.transform.MxTransformManager.java

/**
 * ?//from   w w w  .  jav  a2 s .co  m
 * 
 * @param query
 *            
 * @param target
 *            (?)
 */
protected void transformSingle(QueryDefinition query, TableDefinition target, Map<String, Object> paramMap) {
    logger.debug("------------------------------transformSingle--------------");
    if (!StringUtils.equalsIgnoreCase(query.getTargetTableName(), target.getTableName())) {
        return;
    }
    String taskId = query.getId() + "_exec_0";
    TransformTask task = new TransformTask();
    task.setId(taskId);
    task.setStatus(0);
    task.setQueryId(query.getId());
    task.setTitle(query.getTitle() + "  ");
    task.setSortNo(0);
    JsonFactory f = new JsonFactory();
    ObjectMapper mapper = new ObjectMapper(f);
    Writer w = new StringWriter();
    try {
        mapper.writeValue(w, paramMap);
        task.setParameter(w.toString());
    } catch (Exception e) {
        task.setParameter(JsonUtils.encode(paramMap));
    }
    transformTaskService.save(task);

    MxTransformThread thread = new MxTransformThread(taskId);
    thread.run();
    // org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
    // executor = ContextFactory
    // .getBean("threadPoolTaskExecutor");
    // if (executor != null) {
    // executor.execute(thread);
    // }
}

From source file:org.devgateway.eudevfin.reports.core.utils.ReportTemplate.java

public final String prettyPrint(Document xml) throws Exception {
    Transformer tf = TransformerFactory.newInstance().newTransformer();
    tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    tf.setOutputProperty(OutputKeys.INDENT, "yes");
    Writer out = new StringWriter();
    tf.transform(new DOMSource(xml), new StreamResult(out));
    return out.toString();
}

From source file:ddf.security.pdp.realm.xacml.processor.BalanaClientTest.java

@Test
public void testEvaluateroleuseractionquerycitizenshipUS() throws Exception {
    LOGGER.debug("\n\n\n##### testEvaluate_role_user_action_query_citizenship_US");

    // Setup//from   w  w  w .  j a  v a  2 s.  c om
    File destDir = folder.newFolder(TEMP_DIR_NAME);
    LOGGER.debug("Making directory: {}", destDir.getPath());
    if (destDir.mkdir()) {
        File srcFile = new File(
                projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE);
        FileUtils.copyFileToDirectory(srcFile, destDir);

        RequestType xacmlRequestType = new RequestType();
        xacmlRequestType.setCombinedDecision(false);
        xacmlRequestType.setReturnPolicyIdList(false);

        AttributesType actionAttributes = new AttributesType();
        actionAttributes.setCategory(ACTION_CATEGORY);
        AttributeType actionAttribute = new AttributeType();
        actionAttribute.setAttributeId(ACTION_ID);
        actionAttribute.setIncludeInResult(false);
        AttributeValueType actionValue = new AttributeValueType();
        actionValue.setDataType(STRING_DATA_TYPE);
        actionValue.getContent().add(QUERY_ACTION);
        actionAttribute.getAttributeValue().add(actionValue);
        actionAttributes.getAttribute().add(actionAttribute);

        AttributesType subjectAttributes = new AttributesType();
        subjectAttributes.setCategory(SUBJECT_CATEGORY);
        AttributeType subjectAttribute = new AttributeType();
        subjectAttribute.setAttributeId(SUBJECT_ID);
        subjectAttribute.setIncludeInResult(false);
        AttributeValueType subjectValue = new AttributeValueType();
        subjectValue.setDataType(STRING_DATA_TYPE);
        subjectValue.getContent().add(TEST_USER_1);
        subjectAttribute.getAttributeValue().add(subjectValue);
        subjectAttributes.getAttribute().add(subjectAttribute);

        AttributeType roleAttribute = new AttributeType();
        roleAttribute.setAttributeId(ROLE_CLAIM);
        roleAttribute.setIncludeInResult(false);
        AttributeValueType roleValue = new AttributeValueType();
        roleValue.setDataType(STRING_DATA_TYPE);
        roleValue.getContent().add(ROLE);
        roleAttribute.getAttributeValue().add(roleValue);
        subjectAttributes.getAttribute().add(roleAttribute);

        AttributesType categoryAttributes = new AttributesType();
        categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
        AttributeType citizenshipAttribute = new AttributeType();
        citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
        citizenshipAttribute.setIncludeInResult(false);
        AttributeValueType citizenshipValue = new AttributeValueType();
        citizenshipValue.setDataType(STRING_DATA_TYPE);
        citizenshipValue.getContent().add(US_COUNTRY);
        citizenshipAttribute.getAttributeValue().add(citizenshipValue);
        categoryAttributes.getAttribute().add(citizenshipAttribute);

        xacmlRequestType.getAttributes().add(actionAttributes);
        xacmlRequestType.getAttributes().add(subjectAttributes);
        xacmlRequestType.getAttributes().add(categoryAttributes);

        BalanaClient pdp = new BalanaClient(destDir.getCanonicalPath(), new XmlParser());

        // Perform Test
        ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);

        // Verify
        JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        ObjectFactory objectFactory = new ObjectFactory();
        Writer writer = new StringWriter();
        marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer);
        LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString());
        assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.PERMIT);

        // Cleanup
        LOGGER.debug("Deleting directory: " + destDir);
        FileUtils.deleteDirectory(destDir);
    } else {
        LOGGER.debug("Could not create directory: " + destDir);
    }
}

From source file:ddf.security.pdp.realm.xacml.processor.XacmlClientTest.java

@Test
public void testEvaluateroleuseractionquerycitizenshipUS() throws Exception {
    LOGGER.debug("\n\n\n##### testEvaluate_role_user_action_query_citizenship_US");

    // Setup//  w ww. j  av a 2 s . co  m
    File destDir = folder.newFolder(TEMP_DIR_NAME);
    LOGGER.debug("Making directory: {}", destDir.getPath());
    if (destDir.mkdir()) {
        File srcFile = new File(
                projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE);
        FileUtils.copyFileToDirectory(srcFile, destDir);

        RequestType xacmlRequestType = new RequestType();
        xacmlRequestType.setCombinedDecision(false);
        xacmlRequestType.setReturnPolicyIdList(false);

        AttributesType actionAttributes = new AttributesType();
        actionAttributes.setCategory(ACTION_CATEGORY);
        AttributeType actionAttribute = new AttributeType();
        actionAttribute.setAttributeId(ACTION_ID);
        actionAttribute.setIncludeInResult(false);
        AttributeValueType actionValue = new AttributeValueType();
        actionValue.setDataType(STRING_DATA_TYPE);
        actionValue.getContent().add(QUERY_ACTION);
        actionAttribute.getAttributeValue().add(actionValue);
        actionAttributes.getAttribute().add(actionAttribute);

        AttributesType subjectAttributes = new AttributesType();
        subjectAttributes.setCategory(SUBJECT_CATEGORY);
        AttributeType subjectAttribute = new AttributeType();
        subjectAttribute.setAttributeId(SUBJECT_ID);
        subjectAttribute.setIncludeInResult(false);
        AttributeValueType subjectValue = new AttributeValueType();
        subjectValue.setDataType(STRING_DATA_TYPE);
        subjectValue.getContent().add(TEST_USER_1);
        subjectAttribute.getAttributeValue().add(subjectValue);
        subjectAttributes.getAttribute().add(subjectAttribute);

        AttributeType roleAttribute = new AttributeType();
        roleAttribute.setAttributeId(ROLE_CLAIM);
        roleAttribute.setIncludeInResult(false);
        AttributeValueType roleValue = new AttributeValueType();
        roleValue.setDataType(STRING_DATA_TYPE);
        roleValue.getContent().add(ROLE);
        roleAttribute.getAttributeValue().add(roleValue);
        subjectAttributes.getAttribute().add(roleAttribute);

        AttributesType categoryAttributes = new AttributesType();
        categoryAttributes.setCategory(PERMISSIONS_CATEGORY);
        AttributeType citizenshipAttribute = new AttributeType();
        citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE);
        citizenshipAttribute.setIncludeInResult(false);
        AttributeValueType citizenshipValue = new AttributeValueType();
        citizenshipValue.setDataType(STRING_DATA_TYPE);
        citizenshipValue.getContent().add(US_COUNTRY);
        citizenshipAttribute.getAttributeValue().add(citizenshipValue);
        categoryAttributes.getAttribute().add(citizenshipAttribute);

        xacmlRequestType.getAttributes().add(actionAttributes);
        xacmlRequestType.getAttributes().add(subjectAttributes);
        xacmlRequestType.getAttributes().add(categoryAttributes);

        XacmlClient pdp = new XacmlClient(destDir.getCanonicalPath(), new XmlParser());

        // Perform Test
        ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType);

        // Verify
        JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        ObjectFactory objectFactory = new ObjectFactory();
        Writer writer = new StringWriter();
        marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer);
        LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString());
        assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.PERMIT);

        // Cleanup
        LOGGER.debug("Deleting directory: " + destDir);
        FileUtils.deleteDirectory(destDir);
    } else {
        LOGGER.debug("Could not create directory: " + destDir);
    }
}

From source file:org.echocat.jomon.format.mylyn.MylynWikitextFormatter.java

@Override
public void format(@Nonnull Source source, @Nonnull Target target, @Nullable Hints hints)
        throws IllegalArgumentException, IOException {
    if (!canHandle(source, target, hints)) {
        throw new IllegalArgumentException(
                "Could not handle the combination of " + source + " and " + target + ".");
    }/*w w  w .java  2  s  .c o  m*/
    final Format requestedTargetFormat = target.getFormat();
    final Format targetFormat = Target.Format.textPlain.equals(requestedTargetFormat) ? Target.Format.html
            : requestedTargetFormat;
    final Writer writer = targetFormat.equals(requestedTargetFormat) ? target.getWriter() : new StringWriter();
    final Object markupLanguage = createMarkupLanguageFor(source);
    final Object documentBuilder = createDocumentBuilderFor(targetFormat, writer);
    final Object markupParser = createMarkupParser(markupLanguage, documentBuilder);
    formatWith(source.getReader(), markupParser);
    if (!targetFormat.equals(requestedTargetFormat)) {
        FormatUtils.htmlToPlainText(new StringReader(writer.toString()), target.getWriter());
    }
}

From source file:org.drools.guvnor.server.generators.MultipleKBasesKSessionsGeneratorTest.java

public String toString(final InputStream is) throws IOException {
    if (is != null) {
        final Writer writer = new StringWriter();

        char[] buffer = new char[1024];
        try {//www .  j av  a  2s . c om
            Reader reader = new BufferedReader(new InputStreamReader(is));
            int n;
            while ((n = reader.read(buffer)) != -1) {
                writer.write(buffer, 0, n);
            }
        } finally {
            is.close();
        }
        return writer.toString();
    } else {
        return "";
    }
}

From source file:mitm.djigzo.web.pages.admin.mta.MTAConfig.java

private void apply() {
    Writer writer = new StringWriter();

    try {//from   ww w .j a  va  2  s  . com
        getMainConfig().writeConfig(writer);

        postfixConfigManagerWS.setMainConfig(writer.toString());
        postfixConfigManagerWS.reload();

        applied = true;
    } catch (IOException e) {
        logger.error("Error while applying.", e);

        applyError = true;
    } catch (WebServiceCheckedException e) {
        logger.error("Error while applying.", e);

        applyError = true;
    }
}