Re: java interop help for beginner calling java class

2014-04-01 Thread bww00amd...@yahoo.com
ANother step further 
Thanks for the help..
I set up the diretory struc and can import the class.
Now to get the call working.

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[160];

 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
 /* */   {
 

Re: java interop help for beginner calling java class

2014-04-01 Thread bww00amd...@yahoo.com
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 1)  ; input buffer
n (.read in buf)  ; file read in to decompress
bufout (byte-array 20) ; 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[160];

 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 

Re: java interop help for beginner calling java class

2014-03-29 Thread Chris Shellenbarger
Did you move it to the corresponding directory structure?  So, 
com.example.mystuff would need a directory hierarchy like com/example/mystuff.  
The mystuff directory is where you need to put your java files that are in the 
com.example.mystuff package.

-- 
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.


Re: java interop help for beginner calling java class

2014-03-29 Thread bww00amd...@yahoo.com
Thanks 
I did not set the hierarchy
I will give that a whirl

Regards
Bryan

On Saturday, March 29, 2014 1:07:40 PM UTC-5, Chris Shellenbarger wrote:

 Did you move it to the corresponding directory structure?  So, 
 com.example.mystuff would need a directory hierarchy like 
 com/example/mystuff.  The mystuff directory is where you need to put your 
 java files that are in the com.example.mystuff package.

-- 
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.


java interop help for beginner calling java class

2014-03-28 Thread bww00amd...@yahoo.com
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[160];

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 

Re: java interop help for beginner calling java class

2014-03-28 Thread Tassilo Horn
bww00amd...@yahoo.com bww00amd...@yahoo.com writes:

 I have read so much i cant see the tree for the forest.  and need some
 help calling the ocfLZW class below from clojure.

If that's really the complete class definition...

 /* */ public class OcfLZW
 /* */ {

... then you can't use it from Clojure because it's defined in the
default package.  There's no way to refer to such classes from any other
package except from the default package itself (no matter if from
Clojure or Java).

Solution: Add a

  package my.nice.lzw;

to the top of the java file.  Then you can instantiate it and call its
method's from Clojure like so:

  (let [oi (my.nice.lzw.OcfLZW.);; instantiate an object of that class
s-inefficient ...
out ...]
(.expand oi s-inefficient out)) ;; call its expand() method

HTH,
Tassilo

-- 
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.


Re: java interop help for beginner calling java class

2014-03-28 Thread bryan webb
Thanks the help is much appreciated


 created file ocfLZWBW,java
added 
package my.nice.lzw;   to the top of the file

changed 
/*     */ public class OcfLZW  to  /*     */ public class OcfLZWBW

compiled ocfLZWBW.java to a class file of ocfLZWBW.class  (no errors)

in eclipse added the ocfLZWBW.class files

in eclipse i see public class my.nice.lzw.ocfLZWBW when i use the class file 
editor


added 

(let [oi (my.nice.lzw.OcfLZWBW.)  buff  buffout]  ;; instantiate an object of 
that class 
    (.expand oi buff buffout)) ;; call its expand() method 

fired up the repl 


get a compilerexception
java.lang.ClassNotFoundException: my.nice.lzw.ocfLZWBW







On Friday, March 28, 2014 12:15 PM, Tassilo Horn t...@gnu.org wrote:
 
bww00amd...@yahoo.com bww00amd...@yahoo.com writes:

 I have read so much i cant see the tree for the forest.  and need some
 help calling the ocfLZW class below from clojure.

If that's really the complete class definition...

 /*     */ public class OcfLZW
 /*     */ {

... then you can't use it from Clojure because it's defined in the
default package.  There's no way to refer to such classes from any other
package except from the default package itself (no matter if from
Clojure or Java).

Solution: Add a

  package my.nice.lzw;

to the top of the java file.  Then you can instantiate it and call its
method's from Clojure like so:

  (let [oi (my.nice.lzw.OcfLZW.)    ;; instantiate an object of that class
        s-inefficient ...
        out ...]
    (.expand oi s-inefficient out)) ;; call its expand() method

HTH,
Tassilo

-- 
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.