当前位置: 首页>>代码示例>>Java>>正文


Java StringReader类代码示例

本文整理汇总了Java中java.io.StringReader的典型用法代码示例。如果您正苦于以下问题:Java StringReader类的具体用法?Java StringReader怎么用?Java StringReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StringReader类属于java.io包,在下文中一共展示了StringReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testUnknownLevels

import java.io.StringReader; //导入依赖的package包/类
public void testUnknownLevels() throws IOException {
    TestLevel level = new TestLevel("WARN", 233);
    LogRecord r = new LogRecord(level, "Custom level test");
    Formatter formatter = new LogFormatter();
    String s = formatter.format(r);
    cleanKnownLevels();
    final LogRecord[] rPtr = new LogRecord[] { null };
    Handler h = new Handler() {
        @Override
        public void publish(LogRecord record) {
            rPtr[0] = record;
        }
        @Override
        public void flush() {}
        @Override
        public void close() throws SecurityException {}
    };
    LogRecords.scan(new ReaderInputStream(new StringReader(s)), h);
    assertEquals("level", r.getLevel(), rPtr[0].getLevel());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:LogFormatterTest.java

示例2: verifyInjectedAudience

import java.io.StringReader; //导入依赖的package包/类
@RunAsClient
@Test(groups = TEST_GROUP_CDI,
    description = "Verify that the injected aud claim is as expected")
public void verifyInjectedAudience() throws Exception {
    Reporter.log("Begin verifyInjectedAudience\n");
    String uri = baseURL.toExternalForm() + "/endp/verifyInjectedAudience";
    WebTarget echoEndpointTarget = ClientBuilder.newClient()
        .target(uri)
        .queryParam(Claims.aud.name(), "s6BhdRkqt3")
        .queryParam(Claims.auth_time.name(), authTimeClaim);
    Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
    Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
    String replyString = response.readEntity(String.class);
    JsonReader jsonReader = Json.createReader(new StringReader(replyString));
    JsonObject reply = jsonReader.readObject();
    System.out.println(reply);
    Reporter.log(reply.toString());
    Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
 
开发者ID:eclipse,项目名称:microprofile-jwt-auth,代码行数:20,代码来源:ClaimValueInjectionTest.java

示例3: testSimple2

import java.io.StringReader; //导入依赖的package包/类
public void testSimple2() throws ParseException {
    VarTerm v = new VarTerm("X");
    assertFalse(v.isAtom());
    assertTrue(v.isVar());
    Term t;

    as2jTokenManager tokens = new as2jTokenManager(new SimpleCharStream(new StringReader("Event")));
    Token tk = tokens.getNextToken();
    assertEquals(tk.kind, jason.asSyntax.parser.as2jConstants.VAR);
    
    t = ASSyntax.parseVar("Ea");
    assertFalse(t.isAtom());
    assertTrue(t.isVar());
    
    t = ASSyntax.parseTerm("Event");
    assertFalse(t.isAtom());
    assertTrue(t.isVar());
    
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:20,代码来源:VarTermTest.java

示例4: parseAPDSStatusMessage

import java.io.StringReader; //导入依赖的package包/类
@Override
protected void parseAPDSStatusMessage(Tracon tracon, String messageText) {
	long timestamp = System.currentTimeMillis();

	AirportDataServiceStatus apdsMessage = null;
	try {
		JAXBContext context = JAXBContext.newInstance(AirportDataServiceStatus.class);
		Unmarshaller unmarshaller = context.createUnmarshaller();
		StringReader reader = new StringReader(messageText);
		apdsMessage = (AirportDataServiceStatus) unmarshaller.unmarshal(reader);
	} catch (Exception e) {
		e.printStackTrace();
	}
	Service service = tracon.getService(Constants.APDS);
	if ((service == null) && (DYNAMIC_MODE)) {
		service = new Service();
		service.setName(Constants.APDS);
		tracon.addService(service);
	}
	if (service != null) {
		service.setTimeStamp(timestamp);
		RVRExternalLinks rvrLinks = apdsMessage.getRvrLinks();
		if (rvrLinks != null) {
			for (ExternalLink exLink : rvrLinks.getRvrLink()) {
				handleLink(timestamp, service, tracon.getName(), exLink);
			}
		}
		// Don't set the service status if not configured for override
		boolean changed = false;
		if (!OVERRIDE_STATUS) {
			changed = service.setStatus(getMessageStatus(apdsMessage.getServiceStatus()));
		} else {
			changed = service.refreshStatus();
		}
		if (changed) {
			notificationRepo.save(new Notification(timestamp, service.getStatus(),
					service.getName(), tracon.getName(), NotificationType.SERVICE));
		}
	}
}
 
开发者ID:mshaw323,项目名称:stdds-monitor,代码行数:41,代码来源:StatusMessageParserV4.java

示例5: checkGMLFootprint

import java.io.StringReader; //导入依赖的package包/类
/**
 * Check GML Footprint validity
 */
public static boolean checkGMLFootprint (String footprint)
{
   try
   {
      Configuration configuration = new GMLConfiguration ();
      Parser parser = new Parser (configuration);

      Geometry geom =
            (Geometry) parser.parse (new InputSource (
                  new StringReader (footprint)));
      if (!geom.isEmpty() && !geom.isValid())
      {
         LOGGER.error("Wrong footprint");
         return false;
      }
   }
   catch (Exception e)
   {
      LOGGER.error("Error in extracted footprint: " + e.getMessage());
      return false;
   }
   return true;
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:27,代码来源:ProcessingUtils.java

示例6: createPrincipal

import java.io.StringReader; //导入依赖的package包/类
/**
 * Creates a principal in the KDC with the specified user and password.
 *
 * @param principal principal name, do not include the domain.
 * @param password password.
 * @throws Exception thrown if the principal could not be created.
 */
public synchronized void createPrincipal(String principal, String password)
        throws Exception {
  String orgName= conf.getProperty(ORG_NAME);
  String orgDomain = conf.getProperty(ORG_DOMAIN);
  String baseDn = "ou=users,dc=" + orgName.toLowerCase(Locale.ENGLISH)
                  + ",dc=" + orgDomain.toLowerCase(Locale.ENGLISH);
  String content = "dn: uid=" + principal + "," + baseDn + "\n" +
          "objectClass: top\n" +
          "objectClass: person\n" +
          "objectClass: inetOrgPerson\n" +
          "objectClass: krb5principal\n" +
          "objectClass: krb5kdcentry\n" +
          "cn: " + principal + "\n" +
          "sn: " + principal + "\n" +
          "uid: " + principal + "\n" +
          "userPassword: " + password + "\n" +
          "krb5PrincipalName: " + principal + "@" + getRealm() + "\n" +
          "krb5KeyVersionNumber: 0";

  for (LdifEntry ldifEntry : new LdifReader(new StringReader(content))) {
    ds.getAdminSession().add(new DefaultEntry(ds.getSchemaManager(),
            ldifEntry.getEntry()));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:32,代码来源:MiniKdc.java

示例7: testCharacterReferences

import java.io.StringReader; //导入依赖的package包/类
@Test
public void testCharacterReferences() {
    try {
        URL fileName = EntityTest.class.getResource("testCharRef.xml");
        URL outputFileName = EntityTest.class.getResource("testCharRef.xml.output");
        XMLStreamReader xmlr = factory.createXMLStreamReader(new InputStreamReader(fileName.openStream()));
        int eventType = 0;
        while (xmlr.hasNext()) {
            eventType = xmlr.next();
            handleEvent(xmlr, eventType);
        }
        System.out.println("Output:");
        System.out.println(output);
        Assert.assertTrue(compareOutput(new InputStreamReader(outputFileName.openStream()), new StringReader(output)));
    } catch (Exception ex) {
        ex.printStackTrace();
        Assert.fail(ex.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:EntityTest.java

示例8: testStAXSourceWEmptyNS

import java.io.StringReader; //导入依赖的package包/类
/**
 * @bug 8152530
 * Verifies that StAXSource handles empty namespace properly. NPE was thrown
 * before the fix.
 * @throws Exception if the test fails
 */
@Test
public final void testStAXSourceWEmptyNS() throws Exception {
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
        + "<EntityList>\n"
        + "  <Entity xmlns=\"\">\n"
        + "  </Entity>\n"
        + "  <Entity xmlns=\"\">\n"
        + "  </Entity>\n"
        + "</EntityList> ";

    XMLInputFactory xif = XMLInputFactory.newInstance();
    XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(xml));
    xsr.nextTag();
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer();
    while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT && xsr.getLocalName().equals("Entity")) {
        StringWriter stringResult = new StringWriter();
        t.transform(new StAXSource(xsr), new StreamResult(stringResult));
        System.out.println("result: \n" + stringResult.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:StAXSourceTest.java

示例9: getPanel

import java.io.StringReader; //导入依赖的package包/类
/**
 * Retrieve a JPanel whith the provided SVG drawn on it.
 *
 * @return The JPanel with the SVG drawing
 * @throws java.lang.ClassNotFoundException If the SVGSalamander library
 * could not be found, or if any other error occurred.
 */
public JPanel getPanel() throws ClassNotFoundException {
    /*
     * Use reflection API to create the representation in SVG format
     */
    if (output == null || output.equals(""))
        throw new NullPointerException("SVG output is empty; probably SVG terminal is not used or plot() not executed yet.");
    try {
        SVGUniverse universe = new SVGUniverse();
        universe.loadSVG(new StringReader(output), "plot");
        SVGDiagram diagram = universe.getDiagram(universe.getStreamBuiltURI("plot"));

        SVGDisplayPanel svgDisplayPanel = new SVGDisplayPanel();
        svgDisplayPanel.setDiagram(diagram);
        return svgDisplayPanel;
    } catch (Exception e) {
        throw new ClassNotFoundException(e.getMessage());
    }
}
 
开发者ID:teras,项目名称:JavaPlot,代码行数:26,代码来源:SVGTerminal.java

示例10: parse

import java.io.StringReader; //导入依赖的package包/类
@Override
public T parse(String xml) {
    try {
        JAXBBindings bindings = clazz.getAnnotation(JAXBBindings.class);
        ArrayList<Class<?>> binds = new ArrayList<Class<?>>();
        binds.add(bindings.value());

        for (Class<?> c : bindings.objects()) {
            binds.add(c);
        }

        final JAXBContext context = JAXBContext.newInstance(binds.toArray(new Class<?>[0])); // NOPMD
        return (T) context.createUnmarshaller().unmarshal(new StringReader(xml));
    } catch (JAXBException e) {
        Assert.fail(e.getMessage());
        return null;
    }
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:19,代码来源:JAXBParserImpl.java

示例11: verzendVrijBericht

import java.io.StringReader; //导入依赖的package包/类
@Override
public void verzendVrijBericht(final VrijBerichtGegevens berichtGegevens) {
    LOGGER.debug("Verzenden Vrij Bericht");
    final String endpointUrl = berichtGegevens.getBrpEndpointURI();
    Assert.notNull(endpointUrl, "Endpoint URL leeg");
    final String leveringBericht = berichtGegevens.getArchiveringOpdracht().getData();

    if (leveringBericht != null) {
        LOGGER.info(VERSTUUR_BERICHT_NAAR_ENDPOINT, endpointUrl);
        // Versturen van request
        final Source request = new StreamSource(new StringReader(leveringBericht));
        LOGGER.info("Vrij bericht wordt verstuurd naar endpoint '{}'", endpointUrl);
        MDC.voerUit(zetMDCMDCVeld(berichtGegevens), () -> {
            try {
                verzendingVerwerkVrijBerichtWebServiceClient.verstuurRequest(request, endpointUrl);
            } catch (final WebServiceException e) {
                throw new VerzendExceptie(String.format("Het is niet gelukt om het vrij bericht te verzenden voor partij %1$d : %2$s",
                        berichtGegevens.getArchiveringOpdracht().getOntvangendePartijId(), leveringBericht), e);
            } finally {
                verwijderMDCVelden();
            }
        });
    } else {
        throw new VerzendExceptie(BERICHT_IS_NIET_GEVONDEN_OP_DE_CONTEXT_EN_NIET_VERSTUURD_ENDPOINT + endpointUrl);
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:27,代码来源:BRPStelselServiceImpl.java

示例12: getDescriptionFromManifest

import java.io.StringReader; //导入依赖的package包/类
/**
 * Retrieves the description from an IMS manifest.
 */
public static String getDescriptionFromManifest(Reader xml) throws XmlPullParserException, IOException
{
	StringWriter sr = new StringWriter();
	CharStreams.copy(xml, sr);

	String bufXml = sr.getBuffer().toString();

	String v = getValueForPath("manifest/metadata/lom/general/description/string|langstring", new StringReader(
		bufXml));
	if( v == null )
	{
		v = getValueForPath(
			"manifest/organizations/organization/item/metadata/lom/general/description/string|langstring",
			new StringReader(bufXml));
	}
	return v;
}
 
开发者ID:equella,项目名称:Equella,代码行数:21,代码来源:IMSUtilities.java

示例13: assertParseFailure

import java.io.StringReader; //导入依赖的package包/类
private void assertParseFailure(String jsonString)
{
    try
    {
        JsonParser.readFrom(new StringReader(jsonString));
    }
    catch (JsonParserException e)
    {
        System.out.println("Error detected successfully:");
        System.out.println(e.getMessage());
        return;
    }

    System.err.println("Json compiled successfully when it shouldn't have");
    Assert.fail();
}
 
开发者ID:hadalhw17,项目名称:Artatawe,代码行数:17,代码来源:TestJson.java

示例14: parse

import java.io.StringReader; //导入依赖的package包/类
public static byte[] parse(String s) {
    try {
        int n = s.length();
        ByteArrayOutputStream out = new ByteArrayOutputStream(n >> 1);
        StringReader r = new StringReader(s);
        while (true) {
            int b1 = nextNibble(r);
            if (b1 < 0) {
                break;
            }
            int b2 = nextNibble(r);
            if (b2 < 0) {
                throw new RuntimeException("Invalid string " + s);
            }
            int b = (b1 << 4) | b2;
            out.write(b);
        }
        return out.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:Utils.java

示例15: parse

import java.io.StringReader; //导入依赖的package包/类
void parse() throws SAXException {
    String xml = "<data>\n<broken/>\u0000</data>";

    try {
        InputSource is = new InputSource(new StringReader(xml));
        is.setSystemId("file:///path/to/some.xml");
        // notice that exception thrown here doesn't include the line number
        // information when reported by JVM -- CR6889654
        SAXParserFactory.newInstance().newSAXParser().parse(is, new DefaultHandler());
    } catch (SAXException e) {
        // notice that this message isn't getting displayed -- CR6889649
        throw new SAXException(MSG, e);
    } catch (ParserConfigurationException pce) {

    } catch (IOException ioe) {

    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:Bug6889654Test.java


注:本文中的java.io.StringReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。