/**
  * Serializes the passed object to a byte array, returning a zero byte array if the passed object
  * is null, or fails serialization
  *
  * @param arg The object to serialize
  * @return the serialized object
  */
 public static byte[] serializeNoCompress(Object arg) {
   if (arg == null) return new byte[] {};
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   ObjectOutputStream oos = null;
   try {
     oos = new ObjectOutputStream(baos);
     oos.writeObject(arg);
     oos.flush();
     baos.flush();
     return baos.toByteArray();
   } catch (Exception ex) {
     return new byte[] {};
   } finally {
     try {
       baos.close();
     } catch (Exception ex) {
       /* No Op */
     }
     if (oos != null)
       try {
         oos.close();
       } catch (Exception ex) {
         /* No Op */
       }
   }
 }
Example #2
0
 public static String getLicensee() {
   InputStream is = Q2.class.getResourceAsStream(LICENSEE);
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   if (is != null) {
     BufferedReader br = new BufferedReader(new InputStreamReader(is));
     PrintStream p = new PrintStream(baos);
     p.println();
     p.println();
     try {
       while (br.ready()) p.println(br.readLine());
     } catch (Exception e) {
       e.printStackTrace(p);
     }
   }
   return baos.toString();
 }
Example #3
0
  protected Document encrypt(Document doc) throws GeneralSecurityException, IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    OutputStreamWriter writer = new OutputStreamWriter(os);
    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
    out.output(doc, writer);
    writer.close();

    byte[] crypt = dodes(os.toByteArray(), Cipher.ENCRYPT_MODE);

    Document secureDoc = new Document();
    Element root = new Element(PROTECTED_QBEAN);
    secureDoc.setRootElement(root);
    Element secureData = new Element("data");
    root.addContent(secureData);

    secureData.setText(ISOUtil.hexString(crypt));
    return secureDoc;
  }
 /**
  * Serializes an array of invocation arguments to a byte array
  *
  * @param args The arguments to marshall
  * @return a byte array
  */
 public static byte[] getOutput(Object... args) {
   if (args == null || args.length == 0) return new byte[] {};
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   GZIPOutputStream gzos = null;
   ObjectOutputStream oos = null;
   try {
     gzos = new GZIPOutputStream(baos);
     oos = new ObjectOutputStream(gzos);
     oos.writeObject(args);
     oos.flush();
     gzos.finish();
     gzos.flush();
     baos.flush();
     return baos.toByteArray();
   } catch (Exception ex) {
     throw new RuntimeException(
         "Failed to encode MBeanServerConnection Invocation arguments " + Arrays.toString(args),
         ex);
   } finally {
     try {
       baos.close();
     } catch (Exception ex) {
       /* No Op */
     }
     if (oos != null)
       try {
         oos.close();
       } catch (Exception ex) {
         /* No Op */
       }
     if (gzos != null)
       try {
         gzos.close();
       } catch (Exception ex) {
         /* No Op */
       }
   }
 }