Package org.exoplatform.services.jcr.impl.core.value

Examples of org.exoplatform.services.jcr.impl.core.value.BinaryValue


      testRoot.setProperty(pname, new ByteArrayInputStream(new byte[]{}));

      testRoot.save();

      // change after save
      BinaryValue newexv = (BinaryValue)testRoot.getProperty(pname).getValue();
      long pos = newexv.getLength() + 1024 * 1024 * 5;

      long tmem = Runtime.getRuntime().totalMemory();

      newexv.setLength(pos);

      // apply to the Property and save
      testRoot.getProperty(pname).setValue(newexv);

      long tmemAfter = Runtime.getRuntime().totalMemory();

      if ((tmemAfter - tmem) >= pos)
         log.warn("JVM total memory should not be increased on size of the new Value but does. Was " + tmem
            + " current " + tmemAfter);

      assertEquals("Value data length must be increased ", pos, newexv.getLength());

      newexv = (BinaryValue)testRoot.getProperty(pname).getValue();
      assertEquals("Value data length must be increased ", pos, newexv.getLength());

      // save new size
      testRoot.save();
      newexv = (BinaryValue)testRoot.getProperty(pname).getValue();
      assertEquals("Value data length must be increased ", pos, newexv.getLength());
   }
View Full Code Here


      // create property
      String pname = "file@" + testFile.getName();
      Property p = testRoot.setProperty(pname, new FileInputStream(testFile));

      BinaryValue exv = (BinaryValue)p.getValue();
      long pos = exv.getLength() - (testFile.length() - 20);

      exv.setLength(pos);

      assertEquals("Value data length must be decreased ", pos, exv.getLength());

      // apply to the Property and save
      p.setValue(exv);
      testRoot.save();

      BinaryValue newexv = (BinaryValue)testRoot.getProperty(pname).getValue();
      assertEquals("Value data length must be decreased ", pos, newexv.getLength());
   }
View Full Code Here

         FileOutputStream out = new FileOutputStream(file);
         out.write(buf);
         out.close();

         FileInputStream fs1 = new FileInputStream(file);
         BinaryValue val = new BinaryValue(fs1, SpoolConfig.getDefaultSpoolConfig());
         InputStream str1 = val.getStream();
         assertNotNull(str1);

         // obj returned by getStream() is not the same as incoming stream
         assertNotSame(str1, fs1);

         // streams returned by subsequent call of val.getStream() are equals
         assertEquals(str1, val.getStream());

         // another one value using the same string
         BinaryValue val2 = new BinaryValue(fs1, SpoolConfig.getDefaultSpoolConfig());
         InputStream str2 = val2.getStream();

         // are not the same although created from same Stream
         assertNotSame(str1, str2);

         // stream already consumed
View Full Code Here

      // create property
      String pname = "file@" + testFile.getName();
      Property p = testRoot.setProperty(pname, new ByteArrayInputStream("short message".getBytes()));

      BinaryValue exv = (BinaryValue)p.getValue();
      long pos = exv.getLength() - 5;

      exv.setLength(pos);

      assertEquals("Value data length must be decreased ", pos, exv.getLength());

      // apply to the Property and save
      p.setValue(exv);
      testRoot.save();

      BinaryValue newexv = (BinaryValue)testRoot.getProperty(pname).getValue();
      assertEquals("Value data length must be decreased ", pos, newexv.getLength());
   }
View Full Code Here

   }

   public void testNewBinaryValueFromString() throws Exception
   {

      BinaryValue val =
         new BinaryValue(new ByteArrayInputStream("string".getBytes()), SpoolConfig.getDefaultSpoolConfig());
      InputStream str1 = val.getStream();
      assertNotNull(str1);
      // stream already consumed
      try
      {
         val.getString();
         fail("IllegalStateException should have been thrown");
      }
      catch (IllegalStateException e)
      {
      }

      BinaryValue val2 =
         new BinaryValue(new ByteArrayInputStream("stream".getBytes()), SpoolConfig.getDefaultSpoolConfig());
      String str2 = val2.getString();
      assertNotNull(str2);
      // string already consumed
      try
      {
         val2.getStream();
         fail("IllegalStateException should have been thrown");
      }
      catch (IllegalStateException e)
      {
      }
View Full Code Here

      dataNode.setProperty("jcr:lastModified", Calendar.getInstance());
      dataNode.setProperty("jcr:data", new ByteArrayInputStream(new byte[]{}));

      testRoot.save();

      BinaryValue exv = (BinaryValue)testRoot.getNode(name).getNode("jcr:content").getProperty("jcr:data").getValue();
      long pos = 1024 * 1024 * 5;

      exv.setLength(pos);

      assertEquals("Value data length must be increased ", pos, exv.getLength());

      // apply to the Property and save
      testRoot.getNode(name).getNode("jcr:content").getProperty("jcr:data").setValue(exv);
      testRoot.save();
   }
View Full Code Here

      // create property, prepare the data to be readed
      String pname = "file@" + testFile.getName();
      Property p = testRoot.setProperty(pname, new FileInputStream(testFile));

      BinaryValue exv = (BinaryValue)p.getValue();

      String update1String = "update#1";

      long pos = 1024 * 1024;

      exv.update(new ByteArrayInputStream(update1String.getBytes()), update1String.length(), pos);

      p.setValue(exv);
      testRoot.save();

      // read partial
      exv = (BinaryValue)testRoot.getProperty(pname).getValue();

      ByteArrayOutputStream baos = new ByteArrayOutputStream();

      long res = exv.read(baos, 5, pos + 2); // read 'date#' bytes

      String expected = update1String.substring(2, 7);

      assertEquals(expected.length() + " bytes must be read", expected.length(), res);

      assertEquals("Readed content not equals to expected", expected, new String(baos.toByteArray()));

      // next read
      baos = new ByteArrayOutputStream();
      res = exv.read(baos, 3, pos + 1); // read 'pda' bytes

      expected = update1String.substring(1, 4);

      assertEquals(expected.length() + " bytes must be read", expected.length(), res);

View Full Code Here

      // create property, prepare the data to be readed
      String pname = "file@" + testFile.getName();
      Property p = testRoot.setProperty(pname, new FileInputStream(testFile));

      BinaryValue exv = (BinaryValue)p.getValue();

      String update1String = "update#1";

      long pos = testFile.length();

      exv.update(new ByteArrayInputStream(update1String.getBytes()), update1String.length(), pos);

      p.setValue(exv);
      testRoot.save();

      // read partial greater the value size
      exv = (BinaryValue)testRoot.getProperty(pname).getValue();

      ByteArrayOutputStream baos = new ByteArrayOutputStream();

      long res = exv.read(baos, 1024, pos + 2); // read 'date#1' bytes

      String expected = update1String.substring(2);

      assertEquals(expected.length() + " bytes must be read", expected.length(), res);
View Full Code Here

      // create property, prepare the data to be readed
      String pname = "file@" + testFile.getName();
      Property p = testRoot.setProperty(pname, new ByteArrayInputStream("short message".getBytes()));

      BinaryValue exv = (BinaryValue)p.getValue();

      String update1String = "update#1";

      long pos = 6;

      exv.update(new ByteArrayInputStream(update1String.getBytes()), update1String.length(), pos);

      p.setValue(exv);
      testRoot.save();

      // read partial
      exv = (BinaryValue)testRoot.getProperty(pname).getValue();

      ByteArrayOutputStream baos = new ByteArrayOutputStream();

      long res = exv.read(baos, 5, pos + 2); // read 'date#' bytes

      String expected = update1String.substring(2, 7);

      assertEquals(expected.length() + " bytes must be read", expected.length(), res);
View Full Code Here

      // create property, prepare the data to be readed
      String pname = "file@" + testFile.getName();
      Property p = testRoot.setProperty(pname, new ByteArrayInputStream("short message".getBytes()));

      BinaryValue exv = (BinaryValue)p.getValue();

      String update1String = "update#1";

      long pos = exv.getLength() + 1;

      exv.update(new ByteArrayInputStream(update1String.getBytes()), update1String.length(), pos);

      p.setValue(exv);
      testRoot.save();

      // read partial greater the value size
      exv = (BinaryValue)testRoot.getProperty(pname).getValue();

      ByteArrayOutputStream baos = new ByteArrayOutputStream();

      long res = exv.read(baos, 1024, pos + 2); // read 'date#1' bytes

      String expected = update1String.substring(2);

      assertEquals(expected.length() + " bytes must be read", expected.length(), res);
View Full Code Here

TOP

Related Classes of org.exoplatform.services.jcr.impl.core.value.BinaryValue

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.