Esempio n. 1
0
  @Before
  public void setUp() throws Exception {
    _rgchPwTest = new char[] {'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};

    _fileExisting = File.createTempFile("obzvaultexisting", ".vault");
    _strDecryptedExisting = "existing";
    OBZVaultDocument doc = new OBZVaultDocument();
    doc.setAppVersion("X.Y.DEV");
    doc.setText(_strDecryptedExisting);
    doc.saveAsVaultDoc(_fileExisting, _rgchPwTest);

    _fileText = File.createTempFile("obzvaulttext", ".txt");
    _strText = "Hello world!";
    OutputStream os = new FileOutputStream(_fileText);
    os.write(_strText.getBytes());
    os.close();
  }
 public static void writePackage(KnowledgePackage pkg, File dest) {
   dest.deleteOnExit();
   OutputStream out = null;
   try {
     out = new BufferedOutputStream(new FileOutputStream(dest));
     DroolsStreamUtils.streamOut(out, pkg);
   } catch (Exception e) {
     throw new RuntimeException(e);
   } finally {
     if (out != null) {
       try {
         out.close();
       } catch (IOException e) {
       }
     }
   }
 }
  private void runStreamTest(final int pLength) throws Exception {
    byte[] data = createData(pLength);
    ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
    OutputStream out = new EncoderStream(outBytes, createEncoder(), true);

    try {
      // Provoke failure for encoders that doesn't take array offset properly into account
      int off = (data.length + 1) / 2;
      out.write(data, 0, off);
      if (data.length > off) {
        out.write(data, off, data.length - off);
      }
    } finally {
      out.close();
    }

    byte[] encoded = outBytes.toByteArray();

    //        System.err.println("encoded.length: " + encoded.length);
    //        System.err.println("encoded: " + Arrays.toString(encoded));

    byte[] decoded =
        FileUtil.read(
            new DecoderStream(new ByteArrayInputStream(encoded), createCompatibleDecoder()));
    assertTrue(Arrays.equals(data, decoded));

    InputStream in =
        new DecoderStream(new ByteArrayInputStream(encoded), createCompatibleDecoder());
    outBytes = new ByteArrayOutputStream();

    try {
      FileUtil.copy(in, outBytes);
    } finally {
      outBytes.close();
      in.close();
    }

    decoded = outBytes.toByteArray();
    assertTrue(Arrays.equals(data, decoded));
  }