Package org.exoplatform.services.jcr.impl.dataflow.persistent

Examples of org.exoplatform.services.jcr.impl.dataflow.persistent.FilePersistedValueData


         out.write(data);
      }
      else
      {
         // write file content
         FilePersistedValueData streamed = (FilePersistedValueData)vd;

         InputStream in = null;

         if (streamed.getFile() == null && vd instanceof StreamPersistedValueData)
         {
            if (((StreamPersistedValueData)vd).getTempFile() != null)
            {
               in = PrivilegedFileHelper.fileInputStream(((StreamPersistedValueData)vd).getTempFile());
            }
         }
         else
         {
            in = streamed.getAsStream();
         }

         if (streamed.getFile() instanceof SerializationSpoolFile)
         {
            SerializationSpoolFile ssf = (SerializationSpoolFile)streamed.getFile();
            out.writeString(ssf.getId());
            out.writeLong(0);
         }
         else
         {
View Full Code Here


      long fileSize = file.length();

      if (fileSize > maxBufferSize)
      {
         return new FilePersistedValueData(orderNum, file);
      }
      else
      {
         FileInputStream is = new FileInputStream(file);
         try
View Full Code Here

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

      FilePersistedValueData vd = new FilePersistedValueData(0, file, SpoolConfig.getDefaultSpoolConfig());
      assertFalse(vd.isByteArray());
      assertEquals(10, vd.getLength());
      assertEquals(0, vd.getOrderNumber());
      try
      {
         vd.getAsByteArray();
      }
      catch (IllegalStateException e)
      {
         fail("IllegalStateException should not have been thrown!");
      }
      assertTrue(vd.getAsStream() instanceof FileInputStream);
   }
View Full Code Here

   public void testRemove() throws IOException
   {

      File f = this.createBLOBTempFile("tempFile", 300);

      FilePersistedValueData vd = new FilePersistedValueData(0, f, SpoolConfig.getDefaultSpoolConfig());
      // vd.setMaxBufferSize(200*1024);
      //      assertNull(vd.getFile()); // not spooling by default until getAsStream() will be call

      File serf = File.createTempFile("serialization", "test");

      ObjectWriter wr = new ObjectWriterImpl(new FileOutputStream(serf));

      PersistedValueDataWriter vdw = new PersistedValueDataWriter();
      vdw.write(wr, vd);
      wr.flush();
      wr.close();

      vd = null;

      // read first time
      ObjectReader or = new ObjectReaderImpl(new FileInputStream(serf));

      FilePersistedValueData vd1 = null;

      PersistedValueDataReader vdr = new PersistedValueDataReader(holder, SpoolConfig.getDefaultSpoolConfig());
      try
      {
         vd1 = (FilePersistedValueData)vdr.read(or, PropertyType.BINARY);
      }
      catch (UnknownClassIdException e)
      {
         fail(e.getMessage());
      }

      or.close();
      // Imitation save
      ((StreamPersistedValueData) vd1).setPersistedFile(((StreamPersistedValueData) vd1).getTempFile());

      // read second time
      or = new ObjectReaderImpl(new FileInputStream(serf));
      FilePersistedValueData vd2 = null;

      try
      {
         vd2 = (FilePersistedValueData)vdr.read(or, PropertyType.BINARY);
      }
      catch (UnknownClassIdException e)
      {
         fail(e.getMessage());
      }
      or.close();
      // Imitation save
      ((StreamPersistedValueData) vd2).setPersistedFile(((StreamPersistedValueData) vd2).getTempFile());

      assertTrue(vd1.getFile().exists());
      assertTrue(vd2.getFile().exists());

      // remove first one
      vd1 = null;
      try
      {
         Thread.sleep(1000);
      }
      catch (InterruptedException e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      assertTrue(vd2.getFile().exists());

      f.delete();
   }
View Full Code Here

      long fileSize = file.length();

      if (fileSize > maxBufferSize)
      {
         return new FilePersistedValueData(orderNum, file);
      }
      else
      {
         FileInputStream is = new FileInputStream(file);
         try
View Full Code Here

                        return false;
                     }
                  }
                  else if (another instanceof FilePersistedValueData)
                  {
                     FilePersistedValueData persisted = (FilePersistedValueData)another;

                     // if other persistent - check file
                     dataFile = persisted.getFile();
                  }
                  else
                  {
                     return false;
                  }
View Full Code Here

         out.write(data);
      }
      else
      {
         // write file content
         FilePersistedValueData streamed = (FilePersistedValueData)vd;

         InputStream in = null;

         if (streamed.getFile() == null && vd instanceof StreamPersistedValueData)
         {
            in = PrivilegedFileHelper.fileInputStream(((StreamPersistedValueData)vd).getTempFile());
         }
         else
         {
            in = streamed.getAsStream();
         }

         // TODO optimize it, use channels
         if (streamed.getFile() instanceof SerializationSpoolFile)
         {
            SerializationSpoolFile ssf = (SerializationSpoolFile)streamed.getFile();
            out.writeString(ssf.getId());
            out.writeLong(0);
         }
         else
         {
View Full Code Here

   {
      long fileSize = file.length();

      if (fileSize > spoolConfig.maxBufferSize)
      {
         return new FilePersistedValueData(orderNumber, file, spoolConfig);
      }
      else
      {
         FileInputStream is = new FileInputStream(file);
         try
View Full Code Here

   {
      long fileSize = PrivilegedFileHelper.length(file);

      if (fileSize > maxBufferSize)
      {
         return new FilePersistedValueData(orderNum, file);
      }
      else
      {
         FileInputStream is = PrivilegedFileHelper.fileInputStream(file);
         try
View Full Code Here

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

      FilePersistedValueData vd = new FilePersistedValueData(0, file, SpoolConfig.getDefaultSpoolConfig());
      assertFalse(vd.isByteArray());
      assertEquals(10, vd.getLength());
      assertEquals(0, vd.getOrderNumber());
      try
      {
         vd.getAsByteArray();
      }
      catch (IllegalStateException e)
      {
         fail("IllegalStateException should not have been thrown!");
      }
      assertTrue(vd.getAsStream() instanceof FileInputStream);
   }
View Full Code Here

TOP

Related Classes of org.exoplatform.services.jcr.impl.dataflow.persistent.FilePersistedValueData

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.