Home AMX User Forum Duet/Cafe Duet

ChunkedInputStream

I am massaging some Java code to work in Duet and I have run into an issue with an inputStream. The package contains a class named ChunkedInputStream. The code that uses this inputStream is using the mark() and reset() methods, when the reset() method is called it throws an IOException because pos < 0. I have tried some debugging and found that the actual class of the inputStream at runtime is ceej.net.http.ChunkedInputStream . Not the class from the pacakge the code is in. So I tried fully qualifying the creation of the inputStream:
//this.in = new ChunkedInputStream(in);
this.in = new packageName.ChunkedInputStream(in);
At runtime the class name is still ceej.net.http.ChunkedInputStream , and it still throws an IOException when in.reset() is called. Not sure what is going on here, unless there is somewhere else that the inputStream is being created. Anyone have any ideas?

Or a work around? The code is basically looking at the first four characters of the stream and trying to automatically determine the UTF encoding. After that it calls the reset() method so it can re-read those characters using the known encoding type? I can get the code to work by hard-coding the encoding type but I would perfer not to.

Comments

  • JasonSJasonS Posts: 229
    I have done some more work and I am confused, I have found where the InputStream is coming from but I don't understand how it works...
    public void open() throws exception {
    ...
    }
    
    public Object read(URI uri) throws Exception {
        return new Decoder(open(uri)).decodeDocument();
    }
    

    The Decoder class takes an InputStream as its parameter. I don't understand how it is getting an InputStream from a method that does not return anything?
  • PhreaKPhreaK Posts: 966
    Well that's certainly interesting. Do you have access to the source for your Decoder class? I'd have a look to see what's going on in there.

    Just a head up that if you're using Class.forName(..) anywhere and have set DynamicImport-Package: * this may also be causing some funky behaviour in your class resolution.
  • a_riot42a_riot42 Posts: 1,624
    JasonS wrote: »
    I have done some more work and I am confused, I have found where the InputStream is coming from but I don't understand how it works...
    public void open() throws exception {
    ...
    }
    
    public Object read(URI uri) throws Exception {
        return new Decoder(open(uri)).decodeDocument();
    }
    

    The Decoder class takes an InputStream as its parameter. I don't understand how it is getting an InputStream from a method that does not return anything?

    These don't look like the same methods. One takes an argument and one doesn't. There are likely multiple methods for open() and you have quoted one that takes no arguments. Its hard to help with so little code posted. inputStream is an abstract class so according to the docs "The method reset for class InputStream does nothing except throw an IOException."
    Paul
  • PhreaKPhreaK Posts: 966
    a_riot42 wrote: »
    These don't look like the same methods. One takes an argument and one doesn't.

    Herp derp derp. Completely missed that. Ignore everything I said.
  • JasonSJasonS Posts: 229
    a_riot42 wrote: »
    These don't look like the same methods. One takes an argument and one doesn't. There are likely multiple methods for open() and you have quoted one that takes no arguments. Its hard to help with so little code posted. inputStream is an abstract class so according to the docs "The method reset for class InputStream does nothing except throw an IOException."
    Paul

    That is it! Thank you Paul! There is another open method, I guess I naievely expected overloaded methods to be consecutive in the source. My guess is that the ceej.net.http.ChunkedInputStream is returned as the InputStream whenever a chunked encoding connection is detected. I guess I need to try wraping the ceej.net.http.ChunkedInputStream with the package specific ChunkedInputStream class, but I don't think that will work because the package ChunkedInputStream does not override mark() and reset(). It is irritating because ceej...ChunkedInputStream returns true from markSupported(), although I have no idea which class in the inheritance hiearchy is responding to that method. I guess I need to find a different way to implement the UTF encoding auto detecting code that does not use mark() & reset().

    Any one have any ideas about how to read the first four bytes out of the stream and then put them back after determining the UTF encoding?

    Interesting side note about the ceej classes. Ceej is a proprietary JVM made by a company named Skelmir, apparently this is where AMX gets the JVM. I contacted Skelmir yesterday to see if they could provide JavaDocs for the ChunkedInputStream class. They were very helpfull but indicated that they could not provide that information because it was part of a custom solution that AMX owns. They forwarded my email to the Director of Firmware at AMX, no response as of yet.
  • JasonSJasonS Posts: 229
    AMX and Skelmir have fixed this issue in the latest Hot-Fix firmware 4.1.400. The ceej ChunkedInputStream now responds false to the markSupported() method.
Sign In or Register to comment.