當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。