Package com.ngt.jopenmetaverse.shared.structureddata

Examples of com.ngt.jopenmetaverse.shared.structureddata.OSD


    {
        byte[] contentBinString = { 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x73,
                                    0x69, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x62, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x20, 0x63, 0x6f,
                                    0x6e, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x68,
                                    0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0xa, 0xd };
        OSD llsdBinary = OSD.FromBinary(contentBinString);
        byte[] binaryBinarySerialized = BinaryLLSDOSDParser.SerializeLLSDBinary(llsdBinary);
        Assert.assertArrayEquals(binaryBinString, binaryBinarySerialized);
    }
View Full Code Here


    private static byte[] binaryLongString = (byte[])mergeArrays(binaryHead, binaryLongStringValue);

    @Test
    public void DeserializeString() throws IOException, OSDException
    {
        OSD llsdEmptyString = BinaryLLSDOSDParser.DeserializeLLSDBinary(binaryEmptyString);
        Assert.assertEquals(OSDType.String, llsdEmptyString.getType());
        String contentEmptyString = "";
        Assert.assertEquals(contentEmptyString, llsdEmptyString.asString());

        OSD llsdLongString = BinaryLLSDOSDParser.DeserializeLLSDBinary(binaryLongString);
        Assert.assertEquals(OSDType.String, llsdLongString.getType());
        String contentLongString = "abcdefghijklmnopqrstuvwxyz01234567890";
        Assert.assertEquals(contentLongString, llsdLongString.asString());
    }
View Full Code Here

    }

    @Test
    public void SerializeString() throws Exception
    {
        OSD llsdString = OSD.FromString("abcdefghijklmnopqrstuvwxyz01234567890");
        byte[] binaryLongStringSerialized = BinaryLLSDOSDParser.SerializeLLSDBinary(llsdString);
        Assert.assertArrayEquals(binaryLongString, binaryLongStringSerialized);

        // A test with some utf8 characters
        String contentAStringXML = "<?xml version='1.0'?> <x>&#x196;&#x214;&#x220;&#x228;&#x246;&#x252;</x>";
        byte[] bytes = contentAStringXML.getBytes(Charset.forName("UTF8"));
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(new ByteArrayInputStream(bytes));
        Element rootNode = doc.getDocumentElement();
//        System.out.println("Root element " + doc.getDocumentElement().getNodeName());
        rootNode.normalize();
      
        String contentAString = rootNode.getChildNodes().item(0).getNodeValue();
//        System.out.println("Node Value:" + contentAString);
        OSD llsdAString = OSD.FromString(contentAString);
        byte[] binaryAString = BinaryLLSDOSDParser.SerializeLLSDBinary(llsdAString);
        OSD llsdAStringDS = BinaryLLSDOSDParser.DeserializeLLSDBinary(binaryAString);
        Assert.assertEquals(OSDType.String, llsdAStringDS.getType());
        Assert.assertEquals(contentAString, llsdAStringDS.asString());

        // we also test for a 4byte character.
        String xml = "<x>&#x10137;</x>";
        byte[] bytesTwo = xml.getBytes(Charset.forName("UTF8"));
        DocumentBuilderFactory dbf2 = DocumentBuilderFactory.newInstance();
        DocumentBuilder db2 = dbf2.newDocumentBuilder();
        Document doc2 = db2.parse(new ByteArrayInputStream(bytes));
        Element rootNode2 = doc2.getDocumentElement();
        rootNode2.normalize();
        String contentAString2 = rootNode2.getChildNodes().item(0).getNodeValue();

        OSD llsdStringOne = OSD.FromString(contentAString2);
        byte[] binaryAStringOneSerialized = BinaryLLSDOSDParser.SerializeLLSDBinary(llsdStringOne);
        OSD llsdStringOneDS = BinaryLLSDOSDParser.DeserializeLLSDBinary(binaryAStringOneSerialized);
        Assert.assertEquals(OSDType.String, llsdStringOneDS.getType());
        Assert.assertEquals(contentAString2, llsdStringOneDS.asString());

    }
View Full Code Here

    private static byte[] binaryURI = (byte[])mergeArrays(binaryHead, binaryURIValue);

    @Test
    public void DeserializeURI() throws IOException, OSDException, URISyntaxException
    {
        OSD llsdURI = BinaryLLSDOSDParser.DeserializeLLSDBinary(binaryURI);
        Assert.assertEquals(OSDType.URI, llsdURI.getType());
        URI uri = new URI("http://www.testurl.test/");
        Assert.assertEquals(uri, llsdURI.asUri());

    }
View Full Code Here

    }

    @Test
    public void SerializeURI() throws Exception
    {
        OSD llsdUri = OSD.FromUri(new URI("http://www.testurl.test/"));
        byte[] binaryURISerialized = BinaryLLSDOSDParser.SerializeLLSDBinary(llsdUri);
        Assert.assertArrayEquals(binaryURI, binaryURISerialized);
    }
View Full Code Here

    private static byte[] binaryDateTime = (byte[])mergeArrays(binaryHead, binaryDateTimeValue);

    @Test
    public void DeserializeDateTime() throws IOException, OSDException
    {
        OSD llsdDateTime = BinaryLLSDOSDParser.DeserializeLLSDBinary(binaryDateTime);
        Assert.assertEquals(OSDType.Date, llsdDateTime.getType());
       
      Calendar cal = Calendar.getInstance();
      cal.setTimeZone(TimeZone.getTimeZone("UTC"));
      cal.set(2008, 0, 1, 20, 10, 31);
        cal.set(Calendar.MILLISECOND, 0);
        Date dt = cal.getTime();
        Date dateLocal = llsdDateTime.asDate();
       
//        double t = 9717.36597327148;       
//      //System.out.print("\t" + Utils.bytesToHexString(bytes, "consumed bytes\t"));
//        System.out.print(Utils.bytesToHexString(Utils.doubleToBytes(t), "Double Bytes Big Endian"));
//        System.out.print(Utils.bytesToHexString(Utils.doubleToBytesLit(t), "Double Bytes Lit Endian"));
View Full Code Here

      Calendar cal = Calendar.getInstance();
      cal.setTimeZone(TimeZone.getTimeZone("UTC"));
      cal.set(2008, 0, 1, 20, 10, 31);
        cal.set(Calendar.MILLISECOND, 0);
      Date dt = cal.getTime();
        OSD llsdDate = OSD.FromDate(dt);
        byte[] binaryDateSerialized = BinaryLLSDOSDParser.SerializeLLSDBinary(llsdDate);
//      System.out.println(Utils.bytesToHexString(binaryDateTime, "Original Time"));
//      System.out.println(Utils.bytesToHexString(binaryDateSerialized, "Serialized Time"));     
        Assert.assertArrayEquals(binaryDateTime, binaryDateSerialized);

        // check if a *local* time can be serialized and deserialized
      cal.set(2009, 12, 30, 8, 25, 10);
        Date dtOne = cal.getTime();
        OSD llsdDateOne = OSD.FromDate(dtOne);
        byte[] binaryDateOneSerialized = BinaryLLSDOSDParser.SerializeLLSDBinary(llsdDateOne);
        OSD llsdDateOneDS = BinaryLLSDOSDParser.DeserializeLLSDBinary(binaryDateOneSerialized);
        Assert.assertEquals(OSDType.Date, llsdDateOneDS.getType());
        Assert.assertEquals(dtOne, llsdDateOneDS.asDate());

      cal.set(2010, 11, 11, 10, 8, 20);
        Date dtTwo = cal.getTime();
        OSD llsdDateTwo = OSD.FromDate(dtTwo);
        byte[] binaryDateTwoSerialized = BinaryLLSDOSDParser.SerializeLLSDBinary(llsdDateTwo);
        OSD llsdDateTwoDS = BinaryLLSDOSDParser.DeserializeLLSDBinary(binaryDateTwoSerialized);
        Assert.assertEquals(OSDType.Date, llsdDateOneDS.getType());
        Assert.assertEquals(dtTwo, llsdDateTwoDS.asDate());
    }
View Full Code Here

    private static byte[] binarySimpleArrayTwo = (byte[])mergeArrays(binaryHead, binarySimpleArrayTwoValue);

    @Test
    public void DeserializeArray() throws IOException, OSDException
    {
        OSD llsdEmptyArray = BinaryLLSDOSDParser.DeserializeLLSDBinary(binaryEmptyArray);
        Assert.assertEquals(OSDType.Array, llsdEmptyArray.getType());
        OSDArray llsdEmptyArrayArray = (OSDArray)llsdEmptyArray;
        Assert.assertEquals(0, llsdEmptyArrayArray.count());


        OSD llsdSimpleArray = BinaryLLSDOSDParser.DeserializeLLSDBinary(binarySimpleArray);
        Assert.assertEquals(OSDType.Array, llsdSimpleArray.getType());
        OSDArray llsdArray = (OSDArray)llsdSimpleArray;
        Assert.assertEquals(OSDType.Integer, llsdArray.get(0).getType());
        Assert.assertEquals(0, llsdArray.get(0).asInteger());


        OSD llsdSimpleArrayTwo = BinaryLLSDOSDParser.DeserializeLLSDBinary(binarySimpleArrayTwo);
        Assert.assertEquals(OSDType.Array, llsdSimpleArrayTwo.getType());
        OSDArray llsdArrayTwo = (OSDArray)llsdSimpleArrayTwo;
        Assert.assertEquals(2, llsdArrayTwo.count());

        Assert.assertEquals(OSDType.Integer, llsdArrayTwo.get(0).getType());
        Assert.assertEquals(0, llsdArrayTwo.get(0).asInteger());
View Full Code Here

  {
    String testOne = "[r0.99967899999999998428,r-0.025334599999999998787,r0]";
    String testTwo = "[[r1,r1,r1],r0]";
    String testThree = "{'region_handle':[r255232, r256512], 'position':[r33.6, r33.71, r43.13], 'look_at':[r34.6, r33.71, r43.13]}";

    OSD obj = NotationalLLSDOSDParser.DeserializeLLSDNotation(testOne);
   
    Assert.assertTrue("Expected SDArray, got " + obj.getType().toString(), obj instanceof OSDArray);
    OSDArray array = (OSDArray)obj;
    Assert.assertTrue("Expected three contained objects, got " + array.count(), array.count() == 3);
    Assert.assertTrue("Unexpected value for first real " + array.get(0).asReal(), array.get(0).asReal() > 0.9d && array.get(0).asReal() < 1.0d);
    Assert.assertTrue("Unexpected value for second real " + array.get(1).asReal(), array.get(1).asReal() < 0.0d && array.get(1).asReal() > -0.03d);
    Assert.assertTrue("Unexpected value for third real " + array.get(2).asReal(), array.get(2).asReal() == 0.0d);

    obj = NotationalLLSDOSDParser.DeserializeLLSDNotation(testTwo);
    Assert.assertTrue("Expected SDArray, got " + obj.getType().toString(), obj instanceof OSDArray);
    array = (OSDArray)obj;
    Assert.assertTrue("Expected two contained objects, got " + array.count(), array.count() == 2);
    Assert.assertTrue("Unexpected value for real " + array.get(1).asReal(), array.get(1).asReal() == 0.0d);
    obj = array.get(0);
    Assert.assertTrue("Expected ArrayList, got " + obj.getType().toString(), obj instanceof OSDArray);
    array = (OSDArray)obj;
    Assert.assertTrue("Unexpected value(s) for nested array: " + array.get(0).asReal() + ", " + array.get(1).asReal() + ", " +
        array.get(2).asReal(), array.get(0).asReal() == 1.0d && array.get(1).asReal() == 1.0d && array.get(2).asReal() == 1.0d);

    obj = NotationalLLSDOSDParser.DeserializeLLSDNotation(testThree);
    Assert.assertTrue("Expected LLSDMap, got " + obj.getType().toString(), obj instanceof OSDMap);
    OSDMap hashtable = (OSDMap)obj;
    Assert.assertTrue("Expected three contained objects, got " + hashtable.count(), hashtable.count() == 3);
    Assert.assertTrue(hashtable.get("region_handle") instanceof OSDArray);
    Assert.assertTrue(((OSDArray)hashtable.get("region_handle")).count() == 2);
    Assert.assertTrue(hashtable.get("position") instanceof OSDArray);
View Full Code Here

{
 
  private void testSerialization(String testSD) throws Exception
  {
    byte[] bytes = Utils.stringToBytes(testSD);
    OSD sourceSD =JsonLLSDOSDParser.DeserializeLLSDJson(bytes);
   
    String targetSSD = JsonLLSDOSDParser.SerializeLLSDJsonString(sourceSD);
    System.out.println(targetSSD);
    bytes = Utils.stringToBytes(targetSSD);
    OSD targetSD =JsonLLSDOSDParser.DeserializeLLSDJson(targetSSD);
    TestHelper.compareOSD(sourceSD, targetSD);
  }
View Full Code Here

TOP

Related Classes of com.ngt.jopenmetaverse.shared.structureddata.OSD

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.