private Class<?> getClassFromStream(
     final InputStream stream, final String classname, final File container)
     throws IOException, SecurityException {
   final ByteArrayOutputStream baos = new ByteArrayOutputStream();
   int bytesRead = -1;
   final byte[] buffer = new byte[8192];
   while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
     baos.write(buffer, 0, bytesRead);
   }
   final byte[] classData = baos.toByteArray();
   return this.defineClassFromData(container, classData, classname);
 }
  private byte[] readBytes(InputStream in) {
    byte[] result = null;

    try {
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      byte[] buffer = new byte[BUFFER_SIZE];
      int bytesRead = 0;
      while ((bytesRead = in.read(buffer, 0, BUFFER_SIZE)) != -1) {
        out.write(buffer, 0, bytesRead);
      }
      out.close();

      result = out.toByteArray();
    } catch (IOException ex) {
      Logger.getLogger(getClass()).debug("Error loading Zip entry", ex);
    }

    return (result);
  }
Exemple #3
0
  public static String unzip(String param) {
    try {
      //			byte[] zipArray = new sun.misc.BASE64Decoder().decodeBuffer(param);
      byte[] zipArray = Base64.decodeBase64(param);

      ByteArrayInputStream bif = new ByteArrayInputStream(zipArray);
      //			InflaterInputStream iis = new InflaterInputStream(bif);
      GZIPInputStream gis = new GZIPInputStream(bif);
      ByteArrayOutputStream unZipbof = new ByteArrayOutputStream();
      int position = 0;
      //			for (int read_byte = 0; (read_byte = iis.read()) != -1; position++) {
      for (int read_byte = 0; (read_byte = gis.read()) != -1; position++) {
        unZipbof.write(read_byte);
      }
      unZipbof.flush();

      byte[] unZipbyteArray = unZipbof.toByteArray();
      String returnUnZipString = new String(unZipbyteArray, "UTF-8");
      return returnUnZipString;
    } catch (Exception ex) {
      return null;
    }
  }