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:com.github.rwitzel.streamflyer.experimental.stateful.util.IdleModifierStatePerformanceTest.java

private void assertOverheadByWriter(String input, double expectedMaxSpentTime, double expectedMaxOverhead)
        throws Exception {

    // setup: create modifier and writer
    Writer originalWriter = new StringWriter();
    ModifyingWriter writer = new ModifyingWriter(originalWriter, createIdleModifier());

    // write the stream to an output stream
    long start = System.currentTimeMillis();
    for (int index = 0; index < input.length(); index++) {
        writer.append(input.charAt(index));
    }/*from   ww w .j a va2s  . c  o  m*/
    writer.flush();
    writer.close();
    long end = System.currentTimeMillis();

    originalWriter.toString();

    Writer writer2 = new StringWriter();

    // read the stream into an output stream
    long start2 = System.currentTimeMillis();
    for (int index = 0; index < input.length(); index++) {
        writer2.append(input.charAt(index));
    }
    writer2.flush();
    writer2.close();
    long end2 = System.currentTimeMillis();

    long overhead = (end - start) - (end2 - start2);

    assertTime(end - start, expectedMaxSpentTime, "Time spent by ModifyingWriter:");
    assertTime(overhead, expectedMaxOverhead, "Overhead   by ModifyingWriter:");
}

From source file:org.apache.ambari.server.orm.helpers.dbms.GenericDbmsHelper.java

@Override
public String getDropTableStatement(String tableName) {
    Writer writer = new StringWriter();

    TableDefinition tableDefinition = new TableDefinition();
    tableDefinition.setName(tableName);/*w ww .  jav  a  2 s. co  m*/
    tableDefinition.buildDeletionWriter(createStubAbstractSessionFromPlatform(databasePlatform), writer);

    return writer.toString();
}

From source file:org.dhatim.templating.freemarker.FreeMarkerTemplateProcessor.java

private void applyTemplate(Template template, Element element, ExecutionContext executionContext)
        throws SmooksException {
    // Apply the template...
    String templatingResult;//w  ww. j  a v  a2 s.c om
    try {
        Writer writer = new StringWriter();
        Map<String, Object> model = FreeMarkerUtils.getMergedModel(executionContext);

        template.process(model, writer);
        writer.flush();
        templatingResult = writer.toString();
    } catch (TemplateException e) {
        throw new SmooksException("Failed to apply FreeMarker template to fragment '"
                + DomUtils.getXPath(element) + "'.  Resource: " + config, e);
    } catch (IOException e) {
        throw new SmooksException("Failed to apply FreeMarker template to fragment '"
                + DomUtils.getXPath(element) + "'.  Resource: " + config, e);
    }

    // Create the replacement DOM text node containing the applied template...
    Node resultNode = TextSerializationUnit.createTextElement(element, templatingResult);

    // Process the templating action, supplying the templating result...
    processTemplateAction(element, resultNode, executionContext);
}

From source file:ddf.security.pdp.xacml.processor.BalanaPdpTest.java

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

    final String COUNTRY = "CA";

    testSetup();//w  ww. ja  v a2 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_2);
    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(COUNTRY);
    citizenshipAttribute.getAttributeValue().add(citizenshipValue);
    categoryAttributes.getAttribute().add(citizenshipAttribute);

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

    BalanaPdp pdp = new BalanaPdp(tempDir);

    // 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.DENY);

}

From source file:ca.nrc.cadc.vos.JsonNodeWriterTest.java

@Test
public void writeWithBadNumeric() throws Exception {
    final String testXMLString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<vos:node xmlns:vos=\"http://www.ivoa.net/xml/VOSpace/v2.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" uri=\"vos://cadc.nrc.ca!vospace/OSSOS/measure3\" xsi:type=\"vos:ContainerNode\">\n"
            + "  <vos:properties>\n"
            + "    <vos:property uri=\"ivo://ivoa.net/vospace/core#length\" readOnly=\"true\">-89323123449</vos:property>\n"
            + "    <vos:property uri=\"ivo://ivoa.net/vospace/core#date\" readOnly=\"true\">2016-01-20T15:14:57.443</vos:property>\n"
            + "    <vos:property uri=\"ivo://ivoa.net/vospace/core#groupread\" readOnly=\"false\">ivo://cadc.nrc.ca/gms#OSSOS</vos:property>\n"
            + "    <vos:property uri=\"ivo://ivoa.net/vospace/core#groupwrite\" readOnly=\"false\">ivo://cadc.nrc.ca/gms#OSSOS-Worker ivo://cadc.nrc.ca/gms#OSSOS-Admin</vos:property>\n"
            + "    <vos:property uri=\"ivo://ivoa.net/vospace/core#ispublic\" readOnly=\"false\">false</vos:property>\n"
            + "    <vos:property uri=\"ivo://ivoa.net/vospace/core#creator\" readOnly=\"false\">CN=cadctest_007,OU=cadc,O=hia,C=ca</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/OSSOS#O13AO_object_count\" readOnly=\"false\">0</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#1-object_count-DRYRUN\" readOnly=\"false\">20</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#13AE-object_count\" readOnly=\"false\">0C</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#13AO-object_count\" readOnly=\"false\">16R</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#3-object_count\" readOnly=\"false\">3YU</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#39AO-object_count\" readOnly=\"false\">01</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#4-object_count\" readOnly=\"false\">FG</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#5-object_count\" readOnly=\"false\">RZ</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#H-object_count-DRYRUN\" readOnly=\"false\">1D</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#L-object_count-DRYRUN\" readOnly=\"false\">07</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#O-object_count\" readOnly=\"false\">05</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#O-object_count-DRYRUN\" readOnly=\"false\">0A</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#O13AE-object_count\" readOnly=\"false\">4Q</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#O13AE-object_count-DRYRUN\" readOnly=\"false\">5O</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#O13AO-object_count\" readOnly=\"false\">10C</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#O13AO-object_count-DRYRUN\" readOnly=\"false\">0E</vos:property>\n"
            + "    <vos:property uri=\"ivo://canfar.uvic.ca/ossos#P-object_count-DRYRUN\" readOnly=\"false\">06</vos:property>\n"
            + "  </vos:properties>\n" + "  <vos:nodes>\n"
            + "    <vos:node uri=\"vos://cadc.nrc.ca!vospace/OSSOS/measure3/2013A-E\" xsi:type=\"vos:ContainerNode\">\n"
            + "      <vos:properties>\n"
            + "        <vos:property uri=\"ivo://ivoa.net/vospace/core#length\" readOnly=\"true\">30388581</vos:property>\n"
            + "        <vos:property uri=\"ivo://ivoa.net/vospace/core#date\" readOnly=\"true\">2015-12-17T17:44:17.897</vos:property>\n"
            + "        <vos:property uri=\"ivo://ivoa.net/vospace/core#groupread\" readOnly=\"false\">ivo://cadc.nrc.ca/gms#OSSOS-Admin ivo://cadc.nrc.ca/gms#OSSOS-Worker ivo://cadc.nrc.ca/gms#OSSOS</vos:property>\n"
            + "        <vos:property uri=\"ivo://ivoa.net/vospace/core#groupwrite\" readOnly=\"false\">ivo://cadc.nrc.ca/gms#OSSOS-Worker ivo://cadc.nrc.ca/gms#OSSOS-Admin</vos:property>\n"
            + "        <vos:property uri=\"ivo://ivoa.net/vospace/core#ispublic\" readOnly=\"false\">false</vos:property>\n"
            + "        <vos:property uri=\"ivo://cadc.nrc.ca/vospace/core#islocked\" readOnly=\"false\">true</vos:property>\n"
            + "        <vos:property uri=\"ivo://ivoa.net/vospace/core#creator\" readOnly=\"false\">CN=mtb55_5be,OU=cadc,O=hia,C=ca</vos:property>\n"
            + "      </vos:properties>\n" + "      <vos:nodes />\n" + "    </vos:node>\n"
            + "    <vos:node uri=\"vos://cadc.nrc.ca!vospace/OSSOS/measure3/2013A-E_April9\" xsi:type=\"vos:ContainerNode\">\n"
            + "      <vos:properties>\n"
            + "        <vos:property uri=\"ivo://ivoa.net/vospace/core#length\" readOnly=\"true\">3812708</vos:property>\n"
            + "        <vos:property uri=\"ivo://ivoa.net/vospace/core#date\" readOnly=\"true\">2015-12-17T17:57:32.107</vos:property>\n"
            + "        <vos:property uri=\"ivo://ivoa.net/vospace/core#groupread\" readOnly=\"false\">ivo://cadc.nrc.ca/gms#OSSOS-Admin ivo://cadc.nrc.ca/gms#OSSOS-Worker</vos:property>\n"
            + "        <vos:property uri=\"ivo://ivoa.net/vospace/core#groupwrite\" readOnly=\"false\">ivo://cadc.nrc.ca/gms#OSSOS-Worker ivo://cadc.nrc.ca/gms#OSSOS-Admin</vos:property>\n"
            + "        <vos:property uri=\"ivo://ivoa.net/vospace/core#ispublic\" readOnly=\"false\">false</vos:property>\n"
            + "        <vos:property uri=\"ivo://cadc.nrc.ca/vospace/core#islocked\" readOnly=\"false\">true</vos:property>\n"
            + "        <vos:property uri=\"ivo://ivoa.net/vospace/core#creator\" readOnly=\"false\">CN=mtb55_5be,OU=cadc,O=hia,C=ca</vos:property>\n"
            + "      </vos:properties>\n" + "      <vos:nodes />\n" + "    </vos:node>\n" + "  </vos:nodes>\n"
            + "</vos:node>";

    final String expectedJSONString = "{\n" + "  \"vos:node\" : {\n"
            + "    \"@xmlns:vos\" : \"http://www.ivoa.net/xml/VOSpace/v2.0\",\n"
            + "    \"@xmlns:xsi\" : \"http://www.w3.org/2001/XMLSchema-instance\",\n"
            + "    \"@uri\" : \"vos://cadc.nrc.ca!vospace/OSSOS/measure3\",\n"
            + "    \"@xsi:type\" : \"vos:ContainerNode\",\n" + "    \"vos:properties\" : {\n"
            + "      \"$\" : [\n" + "        {\n"
            + "          \"@uri\" : \"ivo://ivoa.net/vospace/core#length\",\n"
            + "          \"@readOnly\" : \"true\",\n" + "          \"$\" : \"-89323123449\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://ivoa.net/vospace/core#date\",\n"
            + "          \"@readOnly\" : \"true\",\n" + "          \"$\" : \"2016-01-20T15:14:57.443\"\n"
            + "        },\n" + "        {\n"
            + "          \"@uri\" : \"ivo://ivoa.net/vospace/core#groupread\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"ivo://cadc.nrc.ca/gms#OSSOS\"\n"
            + "        },\n" + "        {\n"
            + "          \"@uri\" : \"ivo://ivoa.net/vospace/core#groupwrite\",\n"
            + "          \"@readOnly\" : \"false\",\n"
            + "          \"$\" : \"ivo://cadc.nrc.ca/gms#OSSOS-Worker ivo://cadc.nrc.ca/gms#OSSOS-Admin\"\n"
            + "        },\n" + "        {\n"
            + "          \"@uri\" : \"ivo://ivoa.net/vospace/core#ispublic\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"false\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://ivoa.net/vospace/core#creator\",\n"
            + "          \"@readOnly\" : \"false\",\n"
            + "          \"$\" : \"CN=cadctest_007,OU=cadc,O=hia,C=ca\"\n" + "        },\n" + "        {\n"
            + "          \"@uri\" : \"ivo://canfar.uvic.ca/OSSOS#O13AO_object_count\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"0\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#1-object_count-DRYRUN\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"20\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#13AE-object_count\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"0C\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#13AO-object_count\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"16R\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#3-object_count\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"3YU\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#39AO-object_count\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"01\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#4-object_count\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"FG\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#5-object_count\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"RZ\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#H-object_count-DRYRUN\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"1D\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#L-object_count-DRYRUN\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"07\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#O-object_count\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"05\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#O-object_count-DRYRUN\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"0A\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#O13AE-object_count\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"4Q\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#O13AE-object_count-DRYRUN\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"5O\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#O13AO-object_count\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"10C\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#O13AO-object_count-DRYRUN\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"0E\"\n" + "        },\n"
            + "        {\n" + "          \"@uri\" : \"ivo://canfar.uvic.ca/ossos#P-object_count-DRYRUN\",\n"
            + "          \"@readOnly\" : \"false\",\n" + "          \"$\" : \"06\"\n" + "        }\n"
            + "      ]\n" + "    },\n" + "    \"vos:nodes\" : {\n" + "      \"$\" : [\n" + "        {\n"
            + "          \"@uri\" : \"vos://cadc.nrc.ca!vospace/OSSOS/measure3/2013A-E\",\n"
            + "          \"@xsi:type\" : \"vos:ContainerNode\",\n" + "          \"vos:properties\" : {\n"
            + "            \"$\" : [\n" + "              {\n"
            + "                \"@uri\" : \"ivo://ivoa.net/vospace/core#length\",\n"
            + "                \"@readOnly\" : \"true\",\n" + "                \"$\" : \"30388581\"\n"
            + "              },\n" + "              {\n"
            + "                \"@uri\" : \"ivo://ivoa.net/vospace/core#date\",\n"
            + "                \"@readOnly\" : \"true\",\n"
            + "                \"$\" : \"2015-12-17T17:44:17.897\"\n" + "              },\n"
            + "              {\n" + "                \"@uri\" : \"ivo://ivoa.net/vospace/core#groupread\",\n"
            + "                \"@readOnly\" : \"false\",\n"
            + "                \"$\" : \"ivo://cadc.nrc.ca/gms#OSSOS-Admin ivo://cadc.nrc.ca/gms#OSSOS-Worker ivo://cadc.nrc.ca/gms#OSSOS\"\n"
            + "              },\n" + "              {\n"
            + "                \"@uri\" : \"ivo://ivoa.net/vospace/core#groupwrite\",\n"
            + "                \"@readOnly\" : \"false\",\n"
            + "                \"$\" : \"ivo://cadc.nrc.ca/gms#OSSOS-Worker ivo://cadc.nrc.ca/gms#OSSOS-Admin\"\n"
            + "              },\n" + "              {\n"
            + "                \"@uri\" : \"ivo://ivoa.net/vospace/core#ispublic\",\n"
            + "                \"@readOnly\" : \"false\",\n" + "                \"$\" : \"false\"\n"
            + "              },\n" + "              {\n"
            + "                \"@uri\" : \"ivo://cadc.nrc.ca/vospace/core#islocked\",\n"
            + "                \"@readOnly\" : \"false\",\n" + "                \"$\" : \"true\"\n"
            + "              },\n" + "              {\n"
            + "                \"@uri\" : \"ivo://ivoa.net/vospace/core#creator\",\n"
            + "                \"@readOnly\" : \"false\",\n"
            + "                \"$\" : \"CN=mtb55_5be,OU=cadc,O=hia,C=ca\"\n" + "              }\n"
            + "            ]\n" + "          },\n" + "          \"vos:nodes\" : {\n" + "            \"$\" : [\n"
            + "            ]\n" + "          }\n" + "        },\n" + "        {\n"
            + "          \"@uri\" : \"vos://cadc.nrc.ca!vospace/OSSOS/measure3/2013A-E_April9\",\n"
            + "          \"@xsi:type\" : \"vos:ContainerNode\",\n" + "          \"vos:properties\" : {\n"
            + "            \"$\" : [\n" + "              {\n"
            + "                \"@uri\" : \"ivo://ivoa.net/vospace/core#length\",\n"
            + "                \"@readOnly\" : \"true\",\n" + "                \"$\" : \"3812708\"\n"
            + "              },\n" + "              {\n"
            + "                \"@uri\" : \"ivo://ivoa.net/vospace/core#date\",\n"
            + "                \"@readOnly\" : \"true\",\n"
            + "                \"$\" : \"2015-12-17T17:57:32.107\"\n" + "              },\n"
            + "              {\n" + "                \"@uri\" : \"ivo://ivoa.net/vospace/core#groupread\",\n"
            + "                \"@readOnly\" : \"false\",\n"
            + "                \"$\" : \"ivo://cadc.nrc.ca/gms#OSSOS-Admin ivo://cadc.nrc.ca/gms#OSSOS-Worker\"\n"
            + "              },\n" + "              {\n"
            + "                \"@uri\" : \"ivo://ivoa.net/vospace/core#groupwrite\",\n"
            + "                \"@readOnly\" : \"false\",\n"
            + "                \"$\" : \"ivo://cadc.nrc.ca/gms#OSSOS-Worker ivo://cadc.nrc.ca/gms#OSSOS-Admin\"\n"
            + "              },\n" + "              {\n"
            + "                \"@uri\" : \"ivo://ivoa.net/vospace/core#ispublic\",\n"
            + "                \"@readOnly\" : \"false\",\n" + "                \"$\" : \"false\"\n"
            + "              },\n" + "              {\n"
            + "                \"@uri\" : \"ivo://cadc.nrc.ca/vospace/core#islocked\",\n"
            + "                \"@readOnly\" : \"false\",\n" + "                \"$\" : \"true\"\n"
            + "              },\n" + "              {\n"
            + "                \"@uri\" : \"ivo://ivoa.net/vospace/core#creator\",\n"
            + "                \"@readOnly\" : \"false\",\n"
            + "                \"$\" : \"CN=mtb55_5be,OU=cadc,O=hia,C=ca\"\n" + "              }\n"
            + "            ]\n" + "          },\n" + "          \"vos:nodes\" : {\n" + "            \"$\" : [\n"
            + "            ]\n" + "          }\n" + "        }\n" + "      ]\n" + "    }\n" + "  }\n" + "}";

    final JsonNodeWriter testSubject = new JsonNodeWriter();
    final NodeReader nodeReader = new NodeReader(false);
    final Node rootNode = nodeReader.read(testXMLString);
    final Writer writer = new StringWriter();

    testSubject.write(rootNode, writer);

    final JSONObject expectedJSON = new JSONObject(expectedJSONString);
    final JSONObject resultJSON = new JSONObject(writer.toString());

    assertEquals(expectedJSON, resultJSON, true);
}

From source file:gov.nih.nci.evs.browser.servlet.UploadServlet.java

public String convertStreamToString(InputStream is, long size) throws IOException {

    if (is != null) {
        Writer writer = new StringWriter();
        char[] buffer = new char[(int) size];
        try {/*from   w  w w.j  a v a 2s . c  o  m*/
            Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            int n;
            while ((n = reader.read(buffer)) != -1) {
                writer.write(buffer, 0, n);
            }

        } finally {
            is.close();
        }
        return writer.toString();

    } else {
        return "";
    }

}

From source file:ddf.security.pdp.xacml.processor.BalanaPdpTest.java

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

    // Setup//from w  w w.  j av a  2 s.  c  o  m
    File destDir = folder.newFolder(TEMP_DIR_NAME);
    LOGGER.debug("Making directory: " + destDir.getPath());
    destDir.mkdir();
    File srcFile = new File(
            PROJECT_HOME + 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);

    BalanaPdp pdp = new BalanaPdp(destDir);

    // 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);
}

From source file:ddf.security.pdp.xacml.processor.BalanaPdpTest.java

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

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

    // Perform Test
    BalanaPdp pdp = new BalanaPdp(policyDir);

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

    // By setting the polling interval to a second
    // the policy will be loaded
    pdp.setPollingInterval(1);/*from  w ww . j a va 2 s. co  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:org.lockss.util.TestStreamUtil.java

public void testCopyReader() throws IOException {
    Reader reader = new StringReader("test string");
    Writer writer = new CharArrayWriter(11);
    assertEquals(11, StreamUtil.copy(reader, writer));
    reader.close();/*from  w w  w.ja  v a 2  s.com*/
    String resultStr = writer.toString();
    writer.close();
    assertTrue(resultStr.equals("test string"));
}

From source file:com.siahmsoft.soundwaper.net.SoundcloudApi.java

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

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