类java.io.StringWriter源码实例Demo

下面列出了怎么用java.io.StringWriter的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: netbeans   文件: CountingSecurityManager.java
public static void initialize(String prefix, Mode mode, Set<String> allowedFiles) {
    System.setProperty("counting.security.disabled", "true");

    if (System.getSecurityManager() instanceof CountingSecurityManager) {
        // ok
    } else {
        System.setSecurityManager(new CountingSecurityManager());
    }
    setCnt(0);
    msgs = new StringWriter();
    pw = new PrintWriter(msgs);
    if (prefix != null && Utilities.isWindows()) {
        prefix = prefix.toUpperCase();
    }
    CountingSecurityManager.prefix = prefix;
    CountingSecurityManager.mode = mode;
    allowed = allowedFiles;

    Logger.getLogger("org.netbeans.TopSecurityManager").setLevel(Level.OFF);
    System.setProperty("org.netbeans.TopSecurityManager.level", "3000");
    System.setProperty("counting.security.disabled", "false");
}
 
源代码2 项目: Bytecoder   文件: ModuleTest.java
@Test
public void testFunctionImportBinary() throws IOException {
    final Module module = new Module("mod", "mod.wasm.map");
    final Function function = module.getImports().importFunction(new ImportReference("mod","obj"),"label", PrimitiveType.i32);

    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final StringWriter theSourceMap = new StringWriter();
    final Exporter exporter = new Exporter(debugOptions());
    exporter.export(module, bos, theSourceMap);

    //try (FileOutputStream fos = new FileOutputStream("/home/sertic/Development/Projects/Bytecoder/core/src/test/resources/de/mirkosertic/bytecoder/backend/wasm/ast/testFunctionImport.wasm")) {
    //    exporter.export(module, fos, theSourceMap);
    //}

    final byte[] expected = IOUtils.toByteArray(getClass().getResource("testFunctionImport.wasm"));
    Assert.assertArrayEquals(expected, bos.toByteArray());
    Assert.assertEquals("{\"version\":3,\"file\":\"mod.wasm\",\"sourceRoot\":\"\",\"names\":[],\"sources\":[],\"mappings\":\"\"}", theSourceMap.toString());
}
 
@Test(groups = {
        "wso2.esb" }, description = "WithoutStream B&F, json format, xml evaluators, incoming json, outgoing json ")
public void transformPayloadByArgsValue() throws Exception {

    SimpleHttpClient httpClient = new SimpleHttpClient();
    String payload =
            "{\n" + "    \"id_str\": \"84315710834212866\",\n" + "    \"entities\": {\n" + "        \"urls\": [\n"
                    + "\n" + "        ],\n" + "        \"hashtags\": [\n" + "            {\n"
                    + "                \"text\": \"wso2\",\n" + "                \"indices\": [\n"
                    + "                    35,\n" + "                    45\n" + "                ]\n"
                    + "            }\n" + "        ],\n" + "        \"user_mentions\": [\n" + "\n" + "        ]\n"
                    + "    },\n" + "\n" + "    \"text\": \"Maybe he'll finally find his keys. #peterfalk\",\n"
                    + "    \"user\": {\n" + "        \"id_str\": \"819797\",\n" + "        \"id\": 819797\n"
                    + "    }\n" + "}";

    String contentType = "application/json";
    String url = "http://localhost:8480/services/Dummy";
    Reader data = new StringReader(payload);
    Writer writer = new StringWriter();

    String responsePayload = HttpURLConnectionClient
            .sendPostRequestAndReadResponse(data, new URL(url), writer, contentType);

    assertTrue(responsePayload.contains("wso2"), "Symbol wso2 not found in response message"); // fail

}
 
源代码4 项目: sunbird-lms-service   文件: ProjectUtil.java
public static String getSMSBody(Map<String, String> smsTemplate) {
  try {
    Properties props = new Properties();
    props.put("resource.loader", "class");
    props.put(
        "class.resource.loader.class",
        "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

    VelocityEngine ve = new VelocityEngine();
    ve.init(props);
    smsTemplate.put("newline", "\n");
    smsTemplate.put(
        "instanceName",
        StringUtils.isBlank(smsTemplate.get("instanceName"))
            ? ""
            : smsTemplate.get("instanceName"));
    Template t = ve.getTemplate("/welcomeSmsTemplate.vm");
    VelocityContext context = new VelocityContext(smsTemplate);
    StringWriter writer = new StringWriter();
    t.merge(context, writer);
    return writer.toString();
  } catch (Exception ex) {
    ProjectLogger.log("Exception occurred while formating and sending SMS " + ex);
  }
  return "";
}
 
源代码5 项目: TencentKona-8   文件: T6873849.java
void test(String opt, String expect) throws Exception {
    List<String> args = new ArrayList<String>();
    if (opt != null)
        args.add(opt);
    args.add("-d");
    args.add(testClasses.getPath());
    args.add("-XDrawDiagnostics");
    args.add(new File(testSrc, "T6873849.java").getPath());
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    System.err.println("compile: " + args);
    int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
    pw.close();
    String out = sw.toString();
    System.out.println(out);
    if (rc != 0)
        throw new Exception("compilation failed unexpectedly");
    if (!out.equals(expect))
        throw new Exception("unexpected output from compiler");
}
 
源代码6 项目: neoscada   文件: DebianPackageWriter.java
protected ContentProvider createConfFilesContent () throws IOException
{
    if ( this.confFiles.isEmpty () )
    {
        return ContentProvider.NULL_CONTENT;
    }

    final StringWriter sw = new StringWriter ();

    for ( final String confFile : this.confFiles )
    {
        sw.append ( confFile ).append ( '\n' );
    }

    sw.close ();
    return new StaticContentProvider ( sw.toString () );
}
 
源代码7 项目: virtualview_tools   文件: Log.java
/**
 * Handy function to get a loggable stack trace from a Throwable
 * @param tr An exception to log
 * @return throwable string.
 */
public static String getStackTraceString(Throwable tr) {
    if (tr == null) {
        return "";
    }

    // This is to reduce the amount of log spew that apps do in the non-error
    // condition of the network being unavailable.
    Throwable t = tr;
    while (t != null) {
        if (t instanceof UnknownHostException) {
            return "";
        }
        t = t.getCause();
    }

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    tr.printStackTrace(pw);
    pw.flush();
    return sw.toString();
}
 
/**
 * Returns the String representation of an AlloyRelation's settings.
 */
private static String writeEdgeViz(VizState view, VizState defaultView, AlloyRelation x) throws IOException {
    StringWriter sw = new StringWriter();
    PrintWriter out = new PrintWriter(sw);
    writeDotColor(out, view.edgeColor.get(x), defaultView.edgeColor.get(x));
    writeDotStyle(out, view.edgeStyle.get(x), defaultView.edgeStyle.get(x));
    writeBool(out, "visible", view.edgeVisible.get(x), defaultView.edgeVisible.get(x));
    writeBool(out, "merge", view.mergeArrows.get(x), defaultView.mergeArrows.get(x));
    writeBool(out, "layout", view.layoutBack.get(x), defaultView.layoutBack.get(x));
    writeBool(out, "attribute", view.attribute.get(x), defaultView.attribute.get(x));
    writeBool(out, "constraint", view.constraint.get(x), defaultView.constraint.get(x));
    if (view.weight.get(x) != defaultView.weight.get(x))
        out.write(" weight=\"" + view.weight.get(x) + "\"");
    if (x != null && !view.label.get(x).equals(defaultView.label.get(x)))
        Util.encodeXMLs(out, " label=\"", view.label.get(x), "\"");
    if (out.checkError())
        throw new IOException("PrintWriter IO Exception!");
    return sw.toString();
}
 
源代码9 项目: dremio-oss   文件: PrelSequencer.java
/**
 * Generate readable text and json plans and set them in <code>planHolder</code>
 * @param rel
 * @param explainlevel explain plan level.
 * @param observer
 */
public static String setPlansWithIds(final Prel rel, final SqlExplainLevel explainlevel, final AttemptObserver observer, final long millisTaken) {
  if (rel == null) {
    return null;
  }

  Map<Prel, OpId> relIdMap = getIdMap(rel);
  final StringWriter sw = new StringWriter();
  final RelWriter textPlanWriter = new NumberingRelWriter(relIdMap, new PrintWriter(sw), explainlevel);
  rel.explain(textPlanWriter);

  final String textPlan = sw.toString();
  observer.planText(sw.toString(), millisTaken);
  final RelJsonWriter jsonPlanWriter = new RelJsonWriter(getIdMap(rel), explainlevel);
  rel.explain(jsonPlanWriter);
  observer.planJsonPlan(jsonPlanWriter.asString());
  return textPlan;
}
 
源代码10 项目: netcdf-java   文件: Hdf5NewObjectTable.java
public void setHdf5File(RandomAccessFile raf) throws IOException {
  closeOpenFiles();

  this.location = raf.getLocation();
  List<ObjectBean> beanList = new ArrayList<>();

  iosp = new H5iospNew();
  NetcdfFile ncfile = new NetcdfFileSubclass(iosp, location);
  ncfile.sendIospMessage(H5iospNew.IOSP_MESSAGE_INCLUDE_ORIGINAL_ATTRIBUTES);

  try {
    iosp.open(raf, ncfile, null);
  } catch (Throwable t) {
    StringWriter sw = new StringWriter(20000);
    PrintWriter s = new PrintWriter(sw);
    t.printStackTrace(s);
    dumpTA.setText(sw.toString());
  }

  H5headerNew header = iosp.getHeader();
  for (H5objects.DataObject dataObj : header.getDataObjects()) {
    beanList.add(new ObjectBean(dataObj));
  }

  objectTable.setBeans(beanList);
}
 
源代码11 项目: hop   文件: RemoveWorkflowServletTest.java
@Test
@PrepareForTest( { Encode.class } )
public void testRemoveWorkflowServletEscapesHtmlWhenPipelineNotFound() throws ServletException, IOException {
  HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
  HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );

  StringWriter out = new StringWriter();
  PrintWriter printWriter = new PrintWriter( out );

  PowerMockito.spy( Encode.class );
  when( mockHttpServletRequest.getContextPath() ).thenReturn( RemoveWorkflowServlet.CONTEXT_PATH );
  when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
  when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );

  removeWorkflowServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
  assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );

  PowerMockito.verifyStatic( atLeastOnce() );
  Encode.forHtml( anyString() );
}
 
源代码12 项目: TencentKona-8   文件: ToolBox.java
/**
 * A helper method for executing langtools commands.
 */
private static int genericJavaCMD(
        JavaCMD cmd,
        JavaToolArgs params)
        throws CommandExecutionException, IOException {
    int rc = 0;
    StringWriter sw = null;
    try (PrintWriter pw = (params.errOutput == null) ?
            null : new PrintWriter(sw = new StringWriter())) {
        rc = cmd.run(params, pw);
    }
    String out = (sw == null) ? null : sw.toString();

    if (params.errOutput != null && (out != null) && !out.isEmpty()) {
        params.errOutput.addAll(splitLines(out, lineSeparator));
    }

    if ( (rc == 0 && params.whatToExpect == Expect.SUCCESS) ||
         (rc != 0 && params.whatToExpect == Expect.FAIL) ) {
        return rc;
    }

    throw new CommandExecutionException(cmd.getExceptionMsgContent(params),
            params.whatToExpect);
}
 
源代码13 项目: openjdk-jdk8u   文件: T7190862.java
private String javap(List<String> args, List<String> classes) {
    DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    JavaFileManager fm = JavapFileManager.create(dc, pw);
    JavapTask t = new JavapTask(pw, fm, dc, args, classes);
    if (t.run() != 0)
        throw new Error("javap failed unexpectedly");

    List<Diagnostic<? extends JavaFileObject>> diags = dc.getDiagnostics();
    for (Diagnostic<? extends JavaFileObject> d: diags) {
        if (d.getKind() == Diagnostic.Kind.ERROR)
            throw new Error(d.getMessage(Locale.ENGLISH));
    }
    return sw.toString();

}
 
源代码14 项目: netbeans   文件: TemplateUtil.java
public static String expandTemplate(Reader reader, Map<String, Object> values) {
    StringWriter writer = new StringWriter();
    ScriptEngine eng = getScriptEngine();
    Bindings bind = eng.getContext().getBindings(ScriptContext.ENGINE_SCOPE);
    if (values != null) {
        bind.putAll(values);
    }
    bind.put(ENCODING_PROPERTY_NAME, Charset.defaultCharset().name());
    eng.getContext().setWriter(writer);
    try {
        eng.eval(reader);
    } catch (ScriptException ex) {
        Exceptions.printStackTrace(ex);
    }

    return writer.toString();
}
 
源代码15 项目: jdmn   文件: JsonSerializerTest.java
@Test
public void testPersonSerialization() throws IOException {
    Person person = new Person();
    person.setFirstName("Amy");
    person.setLastName("Smith");
    person.setId(decision.number("38"));
    person.setGender("female");
    person.setList(Arrays.asList("Late payment"));
    person.setMarried(true);
    person.setDateOfBirth(decision.date("2017-01-03"));
    person.setTimeOfBirth(decision.time("11:20:30Z"));
    person.setDateTimeOfBirth(decision.dateAndTime("2016-08-01T12:00:00Z"));
    person.setDateTimeList(Arrays.asList(decision.dateAndTime("2016-08-01T12:00:00Z")));
    person.setYearsAndMonthsDuration(decision.duration("P1Y1M"));
    person.setDaysAndTimeDuration(decision.duration("P2DT20H"));

    Writer writer = new StringWriter();
    JsonSerializer.OBJECT_MAPPER.writeValue(writer, person);
    writer.close();

    assertEquals(personText, writer.toString());
}
 
@Override
public String decompile(InputStream inputStream, String entryName) throws IOException {
  logger.debug("Decompiling... {}", entryName);
  File tempFile = createTempFile(entryName, inputStream);
  tempFile.deleteOnExit();

  String decompiledFileName = getDecompiledFileName(entryName);
  File decompiledFile = new File(decompiledFileName);
  decompiledFile.getParentFile().mkdirs();

  StringWriter pw = new StringWriter();
  try {
    com.strobel.decompiler.Decompiler.decompile(tempFile.getAbsolutePath(), new PlainTextOutput(pw));
  } catch (Exception e) {
    logger.info("Error while decompiling {}. " , entryName);
    throw e;
  }
  pw.flush();

  String decompiledFileContent = pw.toString();
  FileUtils.writeStringToFile(decompiledFile, decompiledFileContent);
  return decompiledFileContent;
}
 
源代码17 项目: htmlunit   文件: DomNode.java
/**
 * Returns a string representation of the XML document from this element and all it's children (recursively).
 * The charset used is the current page encoding.
 * @return the XML string
 */
public String asXml() {
    Charset charsetName = null;
    final HtmlPage htmlPage = getHtmlPageOrNull();
    if (htmlPage != null) {
        charsetName = htmlPage.getCharset();
    }

    final StringWriter stringWriter = new StringWriter();
    try (PrintWriter printWriter = new PrintWriter(stringWriter)) {
        if (charsetName != null && this instanceof HtmlHtml) {
            printWriter.print("<?xml version=\"1.0\" encoding=\"");
            printWriter.print(charsetName);
            printWriter.print("\"?>\r\n");
        }
        printXml("", printWriter);
        return stringWriter.toString();
    }
}
 
源代码18 项目: staedi   文件: StaEDIXMLStreamReaderTest.java
@Test
void testReadXml() throws Exception {
    XMLStreamReader xmlReader = getXmlReader("/x12/extraDelimiter997.edi");
    xmlReader.next(); // Per StAXSource JavaDoc, put in START_DOCUMENT state
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
    StringWriter result = new StringWriter();
    transformer.transform(new StAXSource(xmlReader), new StreamResult(result));
    String resultString = result.toString();
    Diff d = DiffBuilder.compare(Input.fromFile("src/test/resources/x12/extraDelimiter997.xml"))
                        .withTest(resultString).build();
    assertTrue(!d.hasDifferences(), () -> "XML unexpectedly different:\n" + d.toString(new DefaultComparisonFormatter()));
}
 
源代码19 项目: seckill-rocketmq   文件: LogExceptionWapper.java
/**
 * 获取完整栈轨迹
 *
 * @param aThrowable
 * @return
 */
public static String getStackTrace(Throwable aThrowable) {
    final Writer result = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(result);
    aThrowable.printStackTrace(printWriter);
    return result.toString();
}
 
源代码20 项目: TencentKona-8   文件: TestSuperclass.java
String javap(File file) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    String[] args = { file.getPath() };
    int rc = com.sun.tools.javap.Main.run(args, pw);
    pw.close();
    String out = sw.toString();
    if (!out.isEmpty())
        System.err.println(out);
    if (rc != 0)
        throw new Error("javap failed: rc=" + rc);
    return out;
}
 
源代码21 项目: openjdk-jdk8u-backup   文件: CheckMethodAdapter.java
/**
 * Constructs a new {@link CheckMethodAdapter} object. This method adapter
 * will perform basic data flow checks. For instance in a method whose
 * signature is <tt>void m ()</tt>, the invalid instruction IRETURN, or the
 * invalid sequence IADD L2I will be detected.
 *
 * @param access
 *            the method's access flags.
 * @param name
 *            the method's name.
 * @param desc
 *            the method's descriptor (see {@link Type Type}).
 * @param cmv
 *            the method visitor to which this adapter must delegate calls.
 * @param labels
 *            a map of already visited labels (in other methods).
 */
public CheckMethodAdapter(final int access, final String name,
        final String desc, final MethodVisitor cmv,
        final Map<Label, Integer> labels) {
    this(new MethodNode(Opcodes.ASM5, access, name, desc, null, null) {
        @Override
        public void visitEnd() {
            Analyzer<BasicValue> a = new Analyzer<BasicValue>(
                    new BasicVerifier());
            try {
                a.analyze("dummy", this);
            } catch (Exception e) {
                if (e instanceof IndexOutOfBoundsException
                        && maxLocals == 0 && maxStack == 0) {
                    throw new RuntimeException(
                            "Data flow checking option requires valid, non zero maxLocals and maxStack values.");
                }
                e.printStackTrace();
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw, true);
                CheckClassAdapter.printAnalyzerResult(this, a, pw);
                pw.close();
                throw new RuntimeException(e.getMessage() + ' '
                        + sw.toString());
            }
            accept(cmv);
        }
    }, labels);
    this.access = access;
}
 
源代码22 项目: FuzzDroid   文件: Main.java
public static void main(String[] args) {		
	Timer timer = new Timer();
       timer.schedule(new TimerTask() {        	
           @Override
           public void run() {
           	LoggerHelper.logEvent(MyLevel.TIMEOUT, "-1 | Complete analysis stopped due to timeout of 40 minutes");
               System.exit(0);
           }
       }, 40 * 60000);
	
	
	try{
		Main.v().run(args);
		AndroidDebugBridge.terminate();
	}catch(Exception ex) {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		ex.printStackTrace(pw);			
		LoggerHelper.logEvent(MyLevel.EXCEPTION_ANALYSIS, sw.toString());
		UtilMain.writeToFile("mainException.txt", FrameworkOptions.apkPath + "\n");
	}
	LoggerHelper.logEvent(MyLevel.EXECUTION_STOP, "Analysis successfully terminated");
	//this is necessary otherwise we will wait for a max of 20 minutes for the TimerTask
	System.exit(0);
}
 
源代码23 项目: netbeans   文件: ErrorManagerImpl.java
public void notify(int severity, Throwable t) {
    StringWriter w = new StringWriter();
    w.write(prefix);
    w.write(' ');
    t.printStackTrace(new PrintWriter(w));
    
    System.err.println(w.toString());
    
    if (running == null) {
        return;
    }
    running.getLog().println(w.toString());
}
 
源代码24 项目: openjdk-jdk9   文件: TestSuperclass.java
String javap(File file) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    String[] args = { file.getPath() };
    int rc = com.sun.tools.javap.Main.run(args, pw);
    pw.close();
    String out = sw.toString();
    if (!out.isEmpty())
        System.err.println(out);
    if (rc != 0)
        throw new Error("javap failed: rc=" + rc);
    return out;
}
 
源代码25 项目: EasyRouter   文件: EasyRouterLogUtils.java
public static void e(Exception ex) {
    if (!debug) {
        return;
    }
    StringWriter writer = new StringWriter();
    PrintWriter pw = new PrintWriter(writer);
    ex.printStackTrace(pw);
    String string = writer.toString();
    Log.e(DEFAULT_TAG, string);
}
 
源代码26 项目: RxJava2RetrofitDemo   文件: Timber.java
private String getStackTraceString(Throwable t) {
    // Don't replace this bindDisposable Log.getStackTraceString() - it hides
    // UnknownHostException, which is not what we want.
    StringWriter sw = new StringWriter(256);
    PrintWriter pw = new PrintWriter(sw, false);
    t.printStackTrace(pw);
    pw.flush();
    return sw.toString();
}
 
源代码27 项目: dragonwell8_jdk   文件: NTypePrinter.java
protected String printStruct(NStruct nt, char open, char close){
    StringWriter sw = new StringWriter();
    sw.append(open);
    sw.append(nt.name);
    if(nt.fields.size() > 0){
        sw.append('=');
        for(NField f : nt.fields){
            if(f.name != null && f.name.length() > 0)
                sw.append("\"" + f.name + "\"");
            sw.append(print(f.type));
        }
    }
    sw.append(close);
    return sw.toString();
}
 
源代码28 项目: openjdk-jdk8u   文件: XPathNegativeZero.java
private static String xform(final String xml, final String xsl) throws Exception {
    final TransformerFactory tf = TransformerFactory.newInstance();
    final Source xslsrc = new StreamSource(new File(xsl));
    final Templates tmpl = tf.newTemplates(xslsrc);
    final Transformer t = tmpl.newTransformer();

    StringWriter writer = new StringWriter();
    final Source src = new StreamSource(new File(xml));
    final Result res = new StreamResult(writer);

    t.transform(src, res);
    return writer.toString();
}
 
源代码29 项目: jdk8u60   文件: DescriptorTest.java
void javac(String... args) throws Exception {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    int rc = com.sun.tools.javac.Main.compile(args, pw);
    pw.flush();
    String out = sw.toString();
    if (!out.isEmpty())
        System.err.println(out);
    if (rc != 0)
        throw new Exception("compilation failed");
}
 
源代码30 项目: openjdk-jdk8u   文件: DocLintTest.java
void test(List<String> opts, Main.Result expectResult, Set<Message> expectMessages) {
        System.err.println("test: " + opts);
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        List<JavaFileObject> files = Arrays.asList(file);
        try {
            DocumentationTask t = javadoc.getTask(pw, fm, null, null, opts, files);
            boolean ok = t.call();
            pw.close();
            String out = sw.toString().replaceAll("[\r\n]+", "\n");
            if (!out.isEmpty())
                System.err.println(out);
            if (ok && expectResult != Main.Result.OK) {
                error("Compilation succeeded unexpectedly");
            } else if (!ok && expectResult != Main.Result.ERROR) {
                error("Compilation failed unexpectedly");
            } else
                check(out, expectMessages);
        } catch (IllegalArgumentException e) {
            System.err.println(e);
            String expectOut = expectMessages.iterator().next().text;
            if (expectResult != Main.Result.CMDERR)
                error("unexpected exception caught");
            else if (!e.getMessage().equals(expectOut)) {
                error("unexpected exception message: "
                        + e.getMessage()
                        + " expected: " + expectOut);
            }
        }

//        if (errors > 0)
//            throw new Error("stop");
    }
 
 类所在包
 同包方法