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

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


      // 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();

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

      ByteArrayOutputStream baos = new ByteArrayOutputStream();

      // from begin
      long res = exv.read(baos, 0, 0);

      assertEquals("Zero bytes must be read", 0, res);

      assertEquals("Zero bytes must be read", 0, baos.size());

      // from middle
      baos = new ByteArrayOutputStream();

      res = exv.read(baos, 0, 5);

      assertEquals("Zero bytes must be read", 0, res);

      assertEquals("Zero bytes must be read", 0, baos.size());

      // out of end
      try
      {
         exv.read(baos, 0, exv.getLength() + 10);
         fail("The out-of-range exception should be thrown");
      }
      catch (IOException e)
      {
         // ok
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();

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

      ByteArrayOutputStream baos = new ByteArrayOutputStream();

      // from begin
      long res = exv.read(baos, 0, 0);

      assertEquals("Zero bytes must be read", 0, res);

      assertEquals("Zero bytes must be read", 0, baos.size());

      // from middle
      baos = new ByteArrayOutputStream();

      res = exv.read(baos, 0, 1024 * 1024);

      assertEquals("Zero bytes must be read", 0, res);

      assertEquals("Zero bytes must be read", 0, baos.size());

      // out of end
      try
      {
         exv.read(baos, 0, exv.getLength() + 1024);
         fail("The out-of-range exception should be thrown");
      }
      catch (IOException e)
      {
         // ok
View Full Code Here

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

      testRoot.save();

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

      long pos = 0;

      int size = 61440;

      byte[] data = new byte[size];
      Random random = new Random();

      random.nextBytes(data);

      // update
      exv.update(new ByteArrayInputStream(data), size, pos);

      // transient, before the save
      try
      {
View Full Code Here

      NodeType type = node.getPrimaryNodeType();
      assertFalse(type.canAddChildNode("jcr:anyNode"));
      assertFalse(type.canAddChildNode("jcr:anyNode", "nt:base"));
      // assertTrue(type.canSetProperty("jcr:data", new BinaryValue("test")));
      assertFalse(type.canSetProperty("jcr:data",
         new BinaryValue[]{new BinaryValue(new ByteArrayInputStream("test".getBytes()), SpoolConfig
            .getDefaultSpoolConfig())}));
      assertFalse(type.canSetProperty("jcr:notFound", new BinaryValue(new ByteArrayInputStream("test".getBytes()),
         SpoolConfig.getDefaultSpoolConfig())));
      // [PN] 06.03.06 Row below commented
      // assertFalse(type.canSetProperty("jcr:data", new StringValue("test")));
      assertFalse(type.canRemoveItem("jcr:data"));
      assertFalse(type.canRemoveItem("jcr:notFound"));
View Full Code Here

   public void testGetBinaryAsStream() throws RepositoryException, IOException
   {

      node.setProperty("stream",
         new BinaryValue(new ByteArrayInputStream("inputStream".getBytes()), SpoolConfig.getDefaultSpoolConfig()));
      Value value = node.getProperty("stream").getValue();
      InputStream iS = value.getStream();
      byte[] bytes = new byte[iS.available()];
      iS.read(bytes);
      assertEquals("inputStream", new String(bytes));
View Full Code Here

   {

      // System.out.println("STREAM>>>>>>");

      node.setProperty("stream",
         new BinaryValue(new ByteArrayInputStream("inputStream".getBytes()), SpoolConfig.getDefaultSpoolConfig()));
      // System.out.println("STREAM>>>>>>");

      // log.debug("STREAM>>>>>>");
      Value value = node.getProperty("stream").getValue();
      assertEquals("inputStream", value.getString());
View Full Code Here

   }

   public void testGetStream() throws RepositoryException, IOException
   {
      Value value =
         new BinaryValue(new ByteArrayInputStream("inputStream".getBytes()), SpoolConfig.getDefaultSpoolConfig());
      InputStream iS = value.getStream();
      int aval = iS.available();
      byte[] bytes = new byte[iS.available()];
      iS.read(bytes);
      assertEquals("inputStream", new String(bytes));

      // assertEquals(aval, value.getStream().available());
      assertEquals(aval, bytes.length);

      value = session.getValueFactory().createValue("text");
      iS = value.getStream();
      bytes = new byte[2];
      iS.read(bytes);
      assertEquals("te", new String(bytes));
      // Once a Value object has been read once using getStream(),
      // all subsequent calls to getStream() will return the same stream object.
      iS = value.getStream();
      bytes = new byte[2];
      iS.read(bytes);
      assertEquals("xt", new String(bytes));

   }
View Full Code Here

      property = root.getNode("childNode/childNode2/jcr:content").getProperty("jcr:data");

      assertEquals("this is the content", property.getString());
      Value val =
         new BinaryValue(new ByteArrayInputStream("this is the NEW content".getBytes()),
            SpoolConfig.getDefaultSpoolConfig());
      node = root.getNode("childNode/childNode2/jcr:content");
      node.setProperty("jcr:data", val);
      // property.setValue(val);

      node = root.getNode("childNode");
      session.save();
      root = repository.login(credentials, WORKSPACE).getRootNode();
      // System.out.println("------------------");
      property = root.getNode("childNode/childNode2/jcr:content").getProperty("jcr:data");

      assertEquals("this is the NEW content", property.getString());

      session = (SessionImpl)repository.login(credentials, WORKSPACE);
      root = session.getRootNode();
      node = root.getNode("childNode");
      assertEquals(node.toString(), root.getNode("childNode").toString());

      // not allowed!
      // root.getNode("childNode/childNode2/jcr:content").setProperty("myapp:temp",
      // new
      // StringValue("Temp"));

      Session session2 = repository.login(credentials, WORKSPACE);
      Node root2 = session2.getRootNode();
      Node node2 = root2.getNode("childNode/childNode2/jcr:content");
      node2.setProperty("jcr:data",
         new BinaryValue(new ByteArrayInputStream("Temp".getBytes()), SpoolConfig.getDefaultSpoolConfig()));
      session2.save();

      session.refresh(false);

      root = session.getRootNode();
View Full Code Here

      Node contentNode = file.addNode("jcr:content", "nt:resource");
      try
      {
         Value value =
            new BinaryValue(new ByteArrayInputStream("this is the content".getBytes()),
               SpoolConfig.getDefaultSpoolConfig());
         contentNode.setProperty("jcr:data", value);
         contentNode.setProperty("jcr:mimeType", "application/octet-stream");
      }
      catch (IOException e)
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.