private String getUrlContent(CachedUrl url) throws IOException {
   InputStream content = url.getUnfilteredInputStream();
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   StreamUtil.copy(content, baos);
   content.close();
   String contentStr = new String(baos.toByteArray());
   baos.close();
   return contentStr;
 }
Esempio n. 2
0
 private static void testWriteAndRead(ComplexClass cc1)
     throws IOException, ClassNotFoundException {
   ByteArrayOutputStream bout = new ByteArrayOutputStream();
   ObjectOutputStream out = new ObjectOutputStream(bout);
   out.writeObject(cc1);
   out.close();
   ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()));
   ComplexClass cc2 = (ComplexClass) oin.readObject();
   assertEquals(cc1, cc2);
 }
  /**
   * Render status using a given printer.
   *
   * @param status the IRunStatus to render to String
   * @param printer the IRunStatusPrinter to use (defaults to AJC_PRINTER if null)
   * @return the String rendering of the status, or "((IRunStatus) null)" if null
   */
  public static String render(IRunStatus status, IRunStatusPrinter printer) {
    if (null == status) {
      return "((IRunStatus) null)";
    }
    if (null == printer) {
      printer = RunUtils.AJC_PRINTER;
    }
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(outStream);
    printer.printRunStatus(out, status);
    out.flush();

    return outStream.toString();
  }
  /** A deserialized map equals original */
  public void testSerialization() throws Exception {
    ConcurrentNavigableMap q = map5();

    ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
    ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
    out.writeObject(q);
    out.close();

    ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
    ConcurrentNavigableMap r = (ConcurrentNavigableMap) in.readObject();
    assertEquals(q.size(), r.size());
    assertTrue(q.equals(r));
    assertTrue(r.equals(q));
  }
  /** a deserialized serialized atomic holds same value */
  public void testSerialization() {
    AtomicLong l = new AtomicLong();

    try {
      l.set(-22);
      ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
      ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
      out.writeObject(l);
      out.close();

      ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
      ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
      AtomicLong r = (AtomicLong) in.readObject();
      assertEquals(l.get(), r.get());
    } catch (Exception e) {
      unexpectedException();
    }
  }
 private String getRequestAsString(RequestEntity entity) throws Exception {
   ByteArrayOutputStream bos = new ByteArrayOutputStream();
   entity.writeRequest(bos);
   return new String(bos.toByteArray(), "UTF-8");
 }