Advertisement
Guest User

Remedy Attachment Converter

a guest
Jul 31st, 2014
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.91 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.nio.file.Files;
  3. import java.nio.file.Paths;
  4. import java.nio.file.Path;
  5. import java.util.zip.CRC32;
  6. import java.util.zip.Inflater;
  7. import java.util.zip.DataFormatException;
  8.  
  9. public class MoveAttachment {
  10.     private int new_dcom_size;
  11.       private Inflater decompresser = new Inflater(true);
  12.       private CRC32 checksum_worker = new CRC32();
  13.       private byte[] data_bytes;
  14.       private int dbtOffset;
  15.       private int dbtSize;
  16.      
  17.       public void setInput(String inputFile) throws IOException
  18.       {
  19.         Path path = Paths.get(inputFile);
  20.         byte[] data = Files.readAllBytes(path);
  21.         setInput(data);
  22.       }
  23.       public void setInput(byte[] paramArrayOfByte)
  24.       {
  25.         setInput(paramArrayOfByte, 0, paramArrayOfByte.length);
  26.       }
  27.       public void setInput(byte[] paramArrayOfByte, int btOffset, int btSize)
  28.       {
  29.         if ((paramArrayOfByte == null) || (btSize == 0))
  30.         {
  31.           resetDecompressor();
  32.           return;
  33.         }
  34.         if ((btSize < 8) || (paramArrayOfByte[btOffset] != 31) || (paramArrayOfByte[(btOffset + 1)] != -116))
  35.         {
  36.           this.new_dcom_size = 0;
  37.         }
  38.         else
  39.         {
  40.           this.new_dcom_size = (paramArrayOfByte[(btOffset + 4)] & 0xFF);
  41.           this.new_dcom_size |= (paramArrayOfByte[(btOffset + 5)] & 0xFF) << 8;
  42.           this.new_dcom_size |= (paramArrayOfByte[(btOffset + 6)] & 0xFF) << 16;
  43.           this.new_dcom_size |= (paramArrayOfByte[(btOffset + 7)] & 0xFF) << 24;
  44.         }
  45.         this.data_bytes = paramArrayOfByte;
  46.         this.dbtOffset = btOffset;
  47.         this.dbtSize = btSize;
  48.         if (this.new_dcom_size != 0)
  49.         {
  50.           this.decompresser.setInput(paramArrayOfByte, 8 + this.dbtOffset, btSize - 8);
  51.         }
  52.       }
  53.      
  54.       private void resetDecompressor()
  55.       {
  56.         this.data_bytes = null;
  57.         this.dbtOffset = 0;
  58.         this.dbtSize = 0;
  59.         this.new_dcom_size = 0;
  60.         this.checksum_worker.reset();
  61.         this.decompresser .reset();
  62.       }
  63.      
  64.       public byte[] inflate() throws DataFormatException
  65.       {
  66.         if ((this.data_bytes == null) || (this.data_bytes.length == 0)) {
  67.           return null;
  68.         }
  69.         byte[] arrayOfByte = null;
  70.         if (this.new_dcom_size == 0)
  71.         {
  72.           arrayOfByte = this.data_bytes;
  73.         }
  74.         else
  75.         {
  76.           arrayOfByte = new byte[this.new_dcom_size];
  77.           this.decompresser .inflate(arrayOfByte);
  78.           this.checksum_worker.update(arrayOfByte);
  79.           long l = this.checksum_worker.getValue();
  80.           int i = this.dbtOffset + this.dbtSize - 4;
  81.           int j = this.data_bytes[(i++)] & 0xFF;
  82.           j |= (this.data_bytes[(i++)] & 0xFF) << 8;
  83.           j |= (this.data_bytes[(i++)] & 0xFF) << 16;
  84.           j |= (this.data_bytes[(i++)] & 0xFF) << 24;
  85.           if (j != (int)(l & 0xFFFFFFFF))
  86.           {
  87.             resetDecompressor();
  88.             throw new DataFormatException();
  89.           }
  90.         }
  91.         resetDecompressor();
  92.         return arrayOfByte;
  93.       }
  94.      
  95.       public void end()
  96.       {
  97.         this.decompresser.end();
  98.       }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement