java.io.StringWriter Java Examples

The following examples show how to use java.io.StringWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CountingSecurityManager.java    From netbeans with Apache License 2.0 12 votes vote down vote up
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");
}
 
Example #2
Source File: StaEDIXMLStreamReaderTest.java    From staedi with Apache License 2.0 11 votes vote down vote up
@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()));
}
 
Example #3
Source File: T6873849.java    From TencentKona-8 with GNU General Public License v2.0 11 votes vote down vote up
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");
}
 
Example #4
Source File: Timber.java    From RxJava2RetrofitDemo with Apache License 2.0 11 votes vote down vote up
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();
}
 
Example #5
Source File: DebianPackageWriter.java    From neoscada with Eclipse Public License 1.0 10 votes vote down vote up
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 () );
}
 
Example #6
Source File: ProjectUtil.java    From sunbird-lms-service with MIT License 9 votes vote down vote up
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 "";
}
 
Example #7
Source File: ModuleTest.java    From Bytecoder with Apache License 2.0 8 votes vote down vote up
@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());
}
 
Example #8
Source File: T7190862.java    From openjdk-jdk8u with GNU General Public License v2.0 7 votes vote down vote up
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();

}
 
Example #9
Source File: EasyRouterLogUtils.java    From EasyRouter with Apache License 2.0 7 votes vote down vote up
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);
}
 
Example #10
Source File: ZipEntryDecompiler.java    From custom-bytecode-analyzer with GNU General Public License v3.0 7 votes vote down vote up
@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;
}
 
Example #11
Source File: DomNode.java    From htmlunit with Apache License 2.0 7 votes vote down vote up
/**
 * 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();
    }
}
 
Example #12
Source File: Log.java    From virtualview_tools with MIT License 7 votes vote down vote up
/**
 * 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();
}
 
Example #13
Source File: JsonSerializerTest.java    From jdmn with Apache License 2.0 7 votes vote down vote up
@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());
}
 
Example #14
Source File: PrelSequencer.java    From dremio-oss with Apache License 2.0 7 votes vote down vote up
/**
 * 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;
}
 
Example #15
Source File: TemplateUtil.java    From netbeans with Apache License 2.0 7 votes vote down vote up
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();
}
 
Example #16
Source File: ToolBox.java    From TencentKona-8 with GNU General Public License v2.0 7 votes vote down vote up
/**
 * 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);
}
 
Example #17
Source File: RemoveWorkflowServletTest.java    From hop with Apache License 2.0 7 votes vote down vote up
@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() );
}
 
Example #18
Source File: Hdf5NewObjectTable.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
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);
}
 
Example #19
Source File: StaticThemeReaderWriter.java    From org.alloytools.alloy with Apache License 2.0 7 votes vote down vote up
/**
 * 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();
}
 
Example #20
Source File: OAPBPMTest.java    From ltr4l with Apache License 2.0 6 votes vote down vote up
@Test
public void testModelWriteRead() throws Exception {
  ObjectMapper mapper = new ObjectMapper();
  Config config = mapper.readValue(new StringReader(JSON_CONFIG), Config.class);

  PRankTrainer.PRank prankW = new PRankTrainer.PRank(6, 3);
  prankW.weights = new double[]{1.1, 2.2, 3.3, 4.4, 5.5, 6.6};
  prankW.thresholds = new double[]{-10.5, 0.123, 34.5};

  StringWriter savedModel = new StringWriter();
  prankW.writeModel(config, savedModel);

  PRankTrainer.PRank prankR = PRankTrainer.PRank.readModel(new StringReader(savedModel.toString()));

  Assert.assertEquals(6, prankR.weights.length);
  Assert.assertEquals(1.1, prankR.weights[0], 0.001);
  Assert.assertEquals(2.2, prankR.weights[1], 0.001);
  Assert.assertEquals(3.3, prankR.weights[2], 0.001);
  Assert.assertEquals(4.4, prankR.weights[3], 0.001);
  Assert.assertEquals(5.5, prankR.weights[4], 0.001);
  Assert.assertEquals(6.6, prankR.weights[5], 0.001);

  Assert.assertEquals(3, prankR.thresholds.length);
  Assert.assertEquals(-10.5, prankR.thresholds[0], 0.001);
  Assert.assertEquals(0.123, prankR.thresholds[1], 0.001);
  Assert.assertEquals(34.5, prankR.thresholds[2], 0.001);
}
 
Example #21
Source File: ModuleTest.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Test
public void testIntegerMath() throws IOException {

    final StringWriter strWriter = new StringWriter();
    final PrintWriter pw = new PrintWriter(strWriter);

    final Module module = new Module("mod", "mod.wasm.map");

    final FunctionsSection functionsContent = module.getFunctions();
    final Param p1 = param("p1", PrimitiveType.i32);
    final Param p2 = param("p2", PrimitiveType.i32);
    final ExportableFunction function = functionsContent.newFunction("label", Arrays
            .asList(p1, p2), PrimitiveType.i32);

    final Local loc1 = function.newLocal("local1", PrimitiveType.i32);
    function.flow.setLocal(loc1, i32.c(100, null), null);
    function.flow.ret(i32.add(getLocal(loc1, null), i32.c(200, null), null), null);

    final Exporter exporter = new Exporter(debugOptions());
    exporter.export(module, pw);

    final String expected = "(module $mod" + System.lineSeparator()
            + "    (type $t0 (func (param i32) (param i32) (result i32)))" + System.lineSeparator()
            + "    (func $label (type $t0) (param $p1 i32) (param $p2 i32) (result i32)" + System.lineSeparator()
            + "        (local $local1 i32)" + System.lineSeparator()
            + "        (set_local $local1 (i32.const 100))" + System.lineSeparator()
            + "        (return (i32.add (get_local $local1) (i32.const 200)))" + System.lineSeparator()
            + "        )" + System.lineSeparator()
            + "    )";
    Assert.assertEquals(expected, strWriter.toString());
}
 
Example #22
Source File: JsonBody.java    From verano-http with MIT License 6 votes vote down vote up
/**
 * Ctor.
 * @param source Json source
 */
public JsonBody(final JsonSource source) {
    super(() -> {
        final StringWriter writer = new StringWriter();
        Json.createWriter(writer).write(source.json());
        return  new Body(writer.toString());
    });
}
 
Example #23
Source File: HtmlExtractor.java    From validator with Apache License 2.0 6 votes vote down vote up
private String convertToString(final XdmNode element) {
    try {
        final StringWriter writer = new StringWriter();
        final Serializer serializer = this.processor.newSerializer(writer);
        serializer.serializeNode(element);
        return writer.toString();
    } catch (final SaxonApiException e) {
        throw new IllegalStateException("Can not convert to string", e);
    }
}
 
Example #24
Source File: InternalRunnable.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String toString() {
    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    if(runExecuted) {
        pw.println("InternalRunnable.run() executed!");
    }
    pw.println("InternalRunnable.toString() executed!");
    pw.flush();
    return sw.toString();
}
 
Example #25
Source File: FileUtil.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static String writeXMLtoString(Document doc) {
try (StringWriter writer = new StringWriter()) {
    StreamResult streamResult = new StreamResult(writer);
    DOMSource domSource = new DOMSource(doc);
    FileUtil.xmlTransformer.transform(domSource, streamResult);
    return writer.toString();
} catch (Exception e) {
    FileUtil.log.error("Error while writing out XML document to string", e);
    return null;
}
   }
 
Example #26
Source File: DescriptorTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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");
}
 
Example #27
Source File: TestSuperclass.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #28
Source File: UnifiedDiffWriterTest.java    From java-diff-utils with Apache License 2.0 6 votes vote down vote up
@Test
public void testWrite() throws URISyntaxException, IOException {
    String str = readFile(UnifiedDiffReaderTest.class.getResource("jsqlparser_patch_1.diff").toURI(), Charset.defaultCharset());
    UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(new ByteArrayInputStream(str.getBytes()));

    StringWriter writer = new StringWriter();
    UnifiedDiffWriter.write(diff, f -> Collections.EMPTY_LIST, writer, 5);
    System.out.println(writer.toString());
}
 
Example #29
Source File: Main.java    From FuzzDroid with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #30
Source File: SimpleSerialization.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static String getFailureText(final Object orig, final Object copy) {
    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);

    pw.println("Test FAILED: Deserialized object is not equal to the original object");
    pw.print("\tOriginal: ");
    printObject(pw, orig).println();
    pw.print("\tCopy:     ");
    printObject(pw, copy).println();

    pw.close();
    return sw.toString();
}