3

I would like to convert an integer array in java, to an Inputstream, after that I would like to use the stream of bytes to be decompressed using LZMA library.

int [] header = new int[copy.length];

edu.coeia.Compression.LZMA.Decoder decoder = new  edu.coeia.Compression.LZMA.Decoder();
ByteArrayInputStream bStream = new ByteArrayInputStream(bheader);

bStream.coder(// InputSream of bytes);
5
  • What is the range of the values in the header array? Does each entry contain one byte of data or four byte of data? Commented Oct 8, 2011 at 14:12
  • Why is the data being provided as an integer array at all, rather than as bytes? Commented Oct 8, 2011 at 14:49
  • @A.H. The range of values in header is from 0 to 247 bytes. Yes each entry has one byte of data. Commented Oct 8, 2011 at 16:42
  • @EJP the problem that I receive these data from a barcode, which is generated by a C# Code, and the byte streams has the values from 0 to 255, and in Java Byte is -127 to 128, so I converted those bytes to integer array Commented Oct 8, 2011 at 16:43
  • 1
    @Ahmed Saleh You don't have a problem at all. You don't have ints, you have a byte stream, and the bit patterns in the bytes are already correct. The signed/unsigned issue is irrelevant for this purpose. Just feed what you have directly to the decoder as bytes. Commented Oct 8, 2011 at 23:20

1 Answer 1

2

What you need to do is convert the array of integers into an equivalent array of bytes, and then use the ByteArrayInputStream(byte[]) constructor to create the input stream. Finally, decode the stream using the code that you already have.

The first step (conversion) is probably the one that you are having difficulty with, but the code depends on how the bytes are represented in the integer array.

Sign up to request clarification or add additional context in comments.

1 Comment

The problem that I receive those array of integers from a software that was written in C#, hence there is a big difference in byte ordering and values, so whatever I do, I still need to feed the function .Coder an array of bytes that should match the values of the C# software

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.