[x3d-public] X3DJSAIL, X3dToJava.xslt and DOM X3DLoaderObject testing: anotherClassCastException

John Carlson yottzumm at gmail.com
Wed Jun 6 15:51:42 PDT 2018


https://docs.oracle.com/javase/9/docs/api/java/io/InputStream.html#readAllBytes--

InputStream has readAllBytes in java 9.  CRSN.

JOHN

On Wed, Jun 6, 2018, 9:41 AM Don Brutzman <brutzman at nps.edu> wrote:

> 1. Hi John, finally getting back to this one.
>
> On 4/30/2018 3:15 PM, John Carlson wrote:
> > Previously reported problem, now assigned to the X3DLoaderObject, I
> believe.
> >
> > No Viewpoint children in X3D or JSON output.
>
> Not sure what that means?  Viewpoint node typically does not have any
> children, except perhaps for a Metadata* node or an IS/connect.
>
> > Is a problem with X3DLoaderObject, looks like another class cast
> exception.  X3DJSONLD was eliminated from the problem by printing out the
> DOM object, and verifying the Viewpoint objects were there.   See x3d-code/
> www.web3d.org/x3d/stylesheets/java/nashorn/examples/Quotes.js.
> >
> > Can be regenerated by running `ant test.nashorn` in x3d-code/
> www.web3d.org/x3d/stylesheets/java
> >
> > See output in nashorn/examples/Json.{json,x3d}
> >
> > John
>
> OK have recently updated to Java JDK 1.8.0_172 and adjusted PATH to
> confirm jjs is running OK.
>
> Have also synchronized X3DJSAIL sudirectory nashorn/ and contents with
> subversion.
>
> I get the following outputs when running test.nashorn build target:
>
> ============================================================
> ant -f E:\\x3d-code\\www.web3d.org\\x3d\\stylesheets\\java test.nashorn
> test.nashorn:
> ===========================================
> ant nashorn/build.xml test.nashorn
> X3D Nashorn SAI Library.test.nashorn:
> Compile:
> Compiling 1 source file to E:\x3d-code\www.web3d.org
> \x3d\stylesheets\java\classes
> Compiling 1 source file to E:\x3d-code\www.web3d.org
> \x3d\stylesheets\java\classes
> Copy:
> Copying 1 file to E:\x3d-code\www.web3d.org
> \x3d\stylesheets\java\nashorn\examples
> Copying E:\x3d-code\www.web3d.org\x3d\stylesheets\java\examples\HelloWorldProgramOutput.x3d
> to E:\x3d-code\www.web3d.org
> \x3d\stylesheets\java\nashorn\examples\HelloWorldProgramOutput.x3d
> Copying 1 file to E:\x3d-code\www.web3d.org
> \x3d\stylesheets\java\nashorn\examples
> Copying E:\x3d-code\www.web3d.org\x3d\stylesheets\java\examples\HelloWorldProgramOutput.json
> to E:\x3d-code\www.web3d.org
> \x3d\stylesheets\java\nashorn\examples\HelloWorldProgramOutput.json
> Run:
> parameter: source file HelloWorldProgramOutput.x3d filesize 20956 bytes,
> parsed using Document Object Model (DOM) X3DLoader
> parameter: "-tojs" for conversion to X3DJSONLD JavaScript source
> parameter: "-toFile" "nashorn/examples/HelloWorldProgramOutput.Nashorn.js"
> for result file name root nashorn/examples/HelloWorldProgramOutput.Nashorn
> convert to JS JavaScript:
> Warning: toFileJavaScript() is overwriting prior file
> nashorn/examples/HelloWorldProgramOutput.Nashorn.js
> Script DEF=colorTypeConversionScript contains CDATA source-code text,
> copied as "#sourceText" using "strings" mode
> Script DEF=MaterialModulatorScript contains CDATA source-code text, copied
> as "#sourceText" using "strings" mode
> TypeError: input.readAllBytes is not a function
> Error: Cannot read file [E:\x3d-code\www.web3d.org
> \x3d\stylesheets\java\nashorn\node_modules\xmldom\package.json]:
> [Error] TODO problem handling local exception within CommandLine, exiting
> org.web3d.x3d.sai.X3DException: ScriptException when processing fileName
> nashorn\examples\HelloWorldProgramOutput.Nashorn.js.intermediate.js, unable
> to save result: javax.script.ScriptException: Error: Cannot load JSON file
> in nashorn/jvm-npm.js at line number 216 at column number 8
>         at
> org.web3d.x3d.jsail.Core.X3DObject.toFileJavaScript(X3DObject.java:1662)
>         at org.web3d.x3d.jsail.CommandLine.run(CommandLine.java:628)
>         at org.web3d.x3d.jsail.CommandLine.main(CommandLine.java:163)
> parameter: source file HelloWorldProgramOutput.x3d filesize 20956 bytes,
> parsed using Document Object Model (DOM) X3DLoader
> parameter: "-toJSON" for conversion to JSON encoding
> parameter: "-toFile" "nashorn/examples/HelloWorldProgramOutput.Java.json"
> for result file name root nashorn/examples/HelloWorldProgramOutput.Java
> convert to JSON:
> Warning: toFileStylesheetConversion(X3dToJson.xslt) is overwriting prior
> file nashorn/examples/HelloWorldProgramOutput.Java.json
> Script DEF=colorTypeConversionScript contains CDATA source-code text,
> copied as "#sourceText" using "strings" mode
> Script DEF=MaterialModulatorScript contains CDATA source-code text, copied
> as "#sourceText" using "strings" mode
> file conversion successful: HelloWorldProgramOutput.Java.json (39749 bytes)
> parameter: source file HelloWorldProgramOutput.x3d filesize 20956 bytes,
> parsed using Document Object Model (DOM) X3DLoader
> parameter: "-toX3D" for conversion to X3D encoding
> parameter: "-toFile" "nashorn/examples/HelloWorldProgramOutput.Java.x3d"
> for result file name root nashorn/examples/HelloWorldProgramOutput.Java
> convert to X3D:
> Warning: toFileX3D() is overwriting prior file
> nashorn/examples/HelloWorldProgramOutput.Java.x3d
> file conversion successful: HelloWorldProgramOutput.Java.x3d (20956 bytes)
> ===========================================
> ============================================================
>
> As you can see, the exception is in nashorn/jvm-npm.js:
>
>         TypeError: input.readAllBytes is not a function
>
> Header in that file indicates that you have modified it.
>
> Specific javascript code block of interest:
>
>    function readFile (filename, core) {
>      var input;
>      try {
>        if (core) {
>          var classloader =
> java.lang.Thread.currentThread().getContextClassLoader();
>          input = classloader.getResourceAsStream(filename);
>        } else {
>         input = new java.io.FileInputStream(filename);
>        }
>        return new java.lang.String(input.readAllBytes());
>      } catch (e) {
>        System.err.println(e);
>        throw new ModuleError('Cannot read file [' + filename + ']: ',
> 'IO_ERROR', e);
>      }
>    }
>
> JDK 8 Javadoc for java.io.FileInputStream does not provide a
> "readAllBytes()" method.  (Nor does JDK 1.9; however I am currently holding
> at 1.8 to stay compatible with Netbeans 8.)
>
>
> https://docs.oracle.com/javase/8/docs/api/java/io/FileInputStream.html
>
> So it looks like you need another method.
>
> A search for "java.io.FileInputStream readAllBytes" provides a number of
> hits.  For example:
>
>         File to byte[] in Java
>         https://stackoverflow.com/questions/858980/file-to-byte-in-java
>
> 2. Continuing with your prior error console also appears fruitful:
>
> >       [exec] [X3DLoaderObject error] Incorrectly handled object
> construction, current elementObject=ViewpointGroup (ViewpointGroup),
> child=Viewpoint, java.lang.ClassCastException:
> org.web3d.x3d.jsail.Navigation.ViewpointGroupObject cannot be cast to
> org.web3d.x3d.sai.Grouping.X3DGroupingNode
> >
> >       [exec] java.lang.ClassCastException:
> org.web3d.x3d.jsail.Navigation.ViewpointGroupObject cannot be cast to
> org.web3d.x3d.sai.Grouping.X3DGroupingNode
> >
> >       [exec]     at
> org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:1146)
> >
> >       [exec]     at
> org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:542)
> >
> >       [exec]     at
> org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:542)
> >
> >       [exec]     at
> org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:430)
> >
> >       [exec]     at
> org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:399)
> >
> >       [exec]     at
> jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$372$Json$cu1$restOf.:program(nashorn/examples/Json.js:15)
> >
> >       [exec]     at
> jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:655)
> >
> >       [exec]     at
> jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
> >
> >       [exec]     at
> jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:527)
> >
> >       [exec]     at
> jdk.scripting.nashorn/jdk.nashorn.tools.Shell.apply(Shell.java:519)
> >
> >       [exec]     at
> jdk.scripting.nashorn/jdk.nashorn.tools.Shell.runScripts(Shell.java:448)
> >
> >       [exec]     at
> jdk.scripting.nashorn/jdk.nashorn.tools.Shell.run(Shell.java:186)
> >
> >       [exec]     at
> jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:104)
> >
> >       [exec]     at
> jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:80)
>
> Looks like it was trying to treat ViewpointGroup like a X3DGroupingNode -
> but it is not.  ViewpointGroup is not a X3DGroupingNode node, and can only
> contain a Metadata* node, Viewpoint/OrthoViewpoint/GeoViewpoint and other
> ViewpointGroup nodes.
>
> This might have been fixed already as part of the many DOM loader
> improvements performed; not seeing that error in my console.  Worth
> retesting if you can address the readAllBytes issue.
>
> I've added a warning to X3D tooltips to clarify that.
>
> Hope next round of improvement/testing can sort this one out fully.
>
> all the best, Don
> --
> Don Brutzman  Naval Postgraduate School, Code USW/Br
> brutzman at nps.edu
> Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
> X3D graphics, virtual worlds, navy robotics
> http://faculty.nps.edu/brutzman
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20180606/92d8abca/attachment.html>


More information about the x3d-public mailing list