So close!!

i have a question about the called java class and access to the byte array 
from clojure upon  return of the call to java

the call to the method in the class has 2 args buffer in and buffer out. i 
confirmed that the data is in buf and nnnx contains the correct 
size of the uncompressed file. i do not see the uncompressed data in bufout.

(import '(mynicelzw1 OcfLZWBW))
def fbw (new OcfLZWBW)
buf  (byte-array 10000)  ; input buffer
n (.read in buf)  ; file read in to decompress
bufout (byte-array 200000) ; output buffer
nnnx(.expand fbw buf bufout)

When I debug the repl i see the the 
file read in to buf
the call made to .expand in the class OcfLZWBW

I get the correct number of  the size of the uncompressed data (nnnx)

I do not see the uncompressed data in bufout, in the debug bufout is null.

as always any help would be appreciated.

Thanks





On Friday, March 28, 2014 10:12:08 AM UTC-5, bww00...@yahoo.com wrote:
>
> I have read so much i cant see the tree for the forest.
> and need some help calling the  ocfLZW class below from clojure.
>
> THANKS for the help
>
> using eclipse and counterclockwise
>
> In clojure 
>  have the data to decompress read into an array.
>  have an array allocated to hold the decompresed data
>
>
> The java class ocfLZW is accessible
>
> I have a java program exert below that calls the ocfLZW class and verified 
> that it works.
>
>
> FileInputStream fis = new FileInputStream(input);
>             
>             byte[] sInefficient= new byte[(int)input.length()] ;
>             fis.read(sInefficient);
>
>             OcfLZW oi = new OcfLZW();
>
>             byte[] out = null;
>
>                  out = new byte[1600000];
>
>             int len = oi.expand(sInefficient, out);
>                 System.out.println(new String (out));
>                 System.out.println("out size = "+len);
>
>
> ocfLZW java class that does LZW decompress 
>
> /*     */ public class OcfLZW
> /*     */ {
> /*     */   static final int INIT_BITS = 9;
> /*   6 */   final int MAX_BITS = 13;
> /*   7 */   final int TABLE_SIZE = 9029;
> /*   8 */   final int HASH_SHIFT = 5;
> /*   9 */   final int CLEAR_TABLE = 256;
> /*  10 */   final int TERMINATOR = 257;
> /*     */   static final int FIRST_CODE = 258;
> /*     */   static final int CHECK_TIME = 100;
> /*  13 */   final int STACK_SIZE = 4000;
> /*  14 */   boolean EOF = false;
> /*     */   static int myIndex;
> /*     */   static int offset;
> /*     */   static int input_bit_buffer;
> /*     */   static int output_bit_buffer;
> /*     */   static int string_code;
> /*     */   static int bytes_out_this_time;
> /*  22 */   static int next_code = 258;
> /*     */   static int max_code;
> /*  24 */   static int checkpoint = 100;
> /*  25 */   static int tot_bytesin = 0;
> /*     */   static int gbl_ulong;
> /*  28 */   static int[] code_value = null;
> /*  29 */   static int[] prefix_code = null;
> /*  31 */   int input_bit_count = 0;
> /*  32 */   int output_bit_count = 0;
> /*  33 */   int num_bits = 9;
> /*  34 */   int clear_bytesin = 0;
> /*  35 */   int clear_bytesout = 0;
> /*  36 */   int tot_bytesout = 0;
> /*     */   int ratio_new;
> /*  38 */   int ratio_old = 100;
> /*  40 */   static boolean compress_flag = false;
> /*  41 */   static int initialized = 0;
> /*  43 */   static byte[] in_buffpoint = null;
> /*  44 */   static byte[] out_buffpoint = null;
> /*  45 */   int in_buff_n = 0;
> /*  45 */   int out_buff_n = 0;
> /*  45 */   int in_buffend = 0;
> /*  45 */   int out_buffend = 0;
> /*  47 */   byte[] append_character = null;
> /*  48 */   byte gbl_ptr_idx = 0;
> /*  50 */   byte[] decode_stack = null;
> /*  51 */   int ds_i = 0;
> /*     */   
> /*     */   public int expand(byte[] paramArrayOfByte1, byte[] 
> paramArrayOfByte2)
> /*     */   {
> /*  56 */     this.ds_i = 0;
> /*     */     
> /*  58 */     compress_flag = false;
> /*     */     
> /*     */ 
> /*  61 */     max_code = (1 << this.num_bits) - 1;
> /*  62 */     prefix_code = new int[9029];
> /*  63 */     this.append_character = new byte[9029];
> /*     */     
> /*     */ 
> /*     */ 
> /*  67 */     this.decode_stack = new byte[4000];
> /*  69 */     if ((prefix_code == null) || (this.append_character == null) 
> || (this.decode_stack == null) || ((compress_flag) && (code_value == 
> null))) {
> /*  73 */       return 0;
> /*     */     }
> /*  75 */     out_buffpoint = paramArrayOfByte2;
> /*  76 */     this.out_buff_n = 0;
> /*  77 */     in_buffpoint = paramArrayOfByte1;
> /*  78 */     this.in_buff_n = 0;
> /*     */     
> /*     */ 
> /*     */ 
> /*  82 */     int[] arrayOfInt1 = new int[1];
> /*  83 */     int i = 0;
> /*  84 */     int j = 0;
> /*     */     
> /*  86 */     int[] arrayOfInt2 = new int[1];
> /*  87 */     int m = 0;
> /*  88 */     arrayOfInt1[0] = 0;
> /*     */     
> /*  90 */     arrayOfInt2[0] = 0;
> /*     */     
> /*  92 */     int k = 1;
> /*     */     
> /*     */ 
> /*     */ 
> /*     */ 
> /*     */ 
> /*  98 */     inputCode(arrayOfInt1);
> /*  99 */     while ((!this.EOF) && (arrayOfInt1[0] != 257))
> /*     */     {
> /* 100 */       if (k > 0)
> /*     */       {
> /* 101 */         i = arrayOfInt1[0];
> /* 102 */         j = i;
> /* 104 */         if (arrayOfInt1[0] <= 255)
> /*     */         {
> /* 105 */           k = 0;
> /* 106 */           if (putByte(i) == 0) {
> /* 107 */             return 0;
> /*     */           }
> /* 108 */           m++;
> /* 109 */           inputCode(arrayOfInt1);
> /* 110 */           continue;
> /*     */         }
> /*     */       }
> /* 114 */       if (arrayOfInt1[0] == 256)
> /*     */       {
> /* 115 */         k = 1;
> /* 116 */         this.num_bits = 9;
> /* 117 */         next_code = 258;
> /* 118 */         max_code = MAXVAL(this.num_bits);
> /* 119 */         inputCode(arrayOfInt1);
> /*     */       }
> /*     */       else
> /*     */       {
> /* 127 */         if (arrayOfInt1[0] >= next_code)
> /*     */         {
> /* 128 */           this.decode_stack[this.ds_i] = ((byte)j);
> /* 129 */           if (decodeString(arrayOfInt2, this.decode_stack, 
> this.ds_i + 1, i) == 0) {
> /* 130 */             return 0;
> /*     */           }
> /*     */         }
> /* 133 */         else if (decodeString(arrayOfInt2, this.decode_stack, 
> this.ds_i, arrayOfInt1[0]) == 0)
> /*     */         {
> /* 134 */           return 0;
> /*     */         }
> /* 140 */         j = this.decode_stack[arrayOfInt2[0]];
> /* 142 */         while (arrayOfInt2[0] >= this.ds_i)
> /*     */         {
> /* 143 */           int tmp336_335 = 0; int[] tmp336_333 = arrayOfInt2; 
> int tmp338_337 = tmp336_333[tmp336_335];tmp336_333[tmp336_335] = 
> (tmp338_337 - 1);
> /* 143 */           if (putByte(this.decode_stack[tmp338_337]) == 0) {
> /* 144 */             return 0;
> /*     */           }
> /* 145 */           m++;
> /*     */         }
> /* 151 */         if (k == 0)
> /*     */         {
> /* 152 */           if (next_code <= max_code)
> /*     */           {
> /* 153 */             prefix_code[next_code] = i;
> /* 154 */             this.append_character[(next_code++)] = ((byte)j);
> /* 155 */             if ((next_code == max_code) && (this.num_bits < 13)) 
> {
> /* 156 */               max_code = MAXVAL(++this.num_bits);
> /*     */             }
> /*     */           }
> /*     */         }
> /*     */         else {
> /* 160 */           k = 0;
> /*     */         }
> /* 161 */         i = arrayOfInt1[0];
> /* 162 */         inputCode(arrayOfInt1);
> /*     */       }
> /*     */     }
> /* 164 */     return m;
> /*     */   }
> /*     */   
> /*     */   void inputCode(int[] paramArrayOfInt)
> /*     */   {
> /* 168 */     while (this.input_bit_count <= 24)
> /*     */     {
> /* 169 */       if (this.in_buff_n == in_buffpoint.length)
> /*     */       {
> /* 170 */         this.EOF = true;
> /* 171 */         break;
> /*     */       }
> /* 173 */       tot_bytesin += 1;
> /* 174 */       paramArrayOfInt[0] = (in_buffpoint[(this.in_buff_n++)] & 
> 0xFF);
> /*     */       
> /* 176 */       input_bit_buffer |= paramArrayOfInt[0] << 24 - 
> this.input_bit_count;
> /* 177 */       this.input_bit_count += 8;
> /*     */     }
> /* 180 */     if (!this.EOF)
> /*     */     {
> /* 181 */       paramArrayOfInt[0] = (input_bit_buffer >>> 32 - 
> this.num_bits);
> /* 182 */       input_bit_buffer <<= this.num_bits;
> /* 183 */       this.input_bit_count -= this.num_bits;
> /*     */     }
> /*     */   }
> /*     */   
> /*     */   int putByte(int paramInt)
> /*     */   {
> /* 198 */     if (this.tot_bytesout == out_buffpoint.length) {
> /* 199 */       return 0;
> /*     */     }
> /* 201 */     out_buffpoint[this.tot_bytesout] = ((byte)paramInt);
> /* 202 */     this.tot_bytesout += 1;
> /* 203 */     return 1;
> /*     */   }
> /*     */   
> /*     */   int MAXVAL(int paramInt)
> /*     */   {
> /* 207 */     return (1 << paramInt) - 1;
> /*     */   }
> /*     */   
> /*     */   int decodeString(int[] paramArrayOfInt, byte[] 
> paramArrayOfByte, int paramInt1, int paramInt2)
> /*     */   {
> /* 217 */     gbl_ulong = paramInt2;
> /* 218 */     myIndex = 0;
> /* 219 */     while (gbl_ulong > 255)
> /*     */     {
> /* 220 */       if (gbl_ulong >= 9029) {
> /* 221 */         return 0;
> /*     */       }
> /* 224 */       paramArrayOfByte[(paramInt1++)] = 
> this.append_character[gbl_ulong];
> /* 225 */       gbl_ulong = prefix_code[gbl_ulong];
> /* 227 */       if (myIndex++ >= 4000) {
> /* 228 */         return 0;
> /*     */       }
> /*     */     }
> /* 230 */     paramArrayOfByte[paramInt1] = ((byte)gbl_ulong);
> /* 231 */     paramArrayOfInt[0] = paramInt1;
> /* 232 */     return 1;
> /*     */   }
> /*     */ }
>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to