Package org.exoplatform.services.jcr.impl.util.io

Examples of org.exoplatform.services.jcr.impl.util.io.FileCleaner


   public void setUp() throws Exception
   {
      super.setUp();

      testFile = new File(parentDir, FILE_NAME);
      testCleaner = new FileCleaner(CLEANER_TIMEOUT);

      SwapFile sf = SwapFile.get(parentDir, FILE_NAME,testCleaner);
      FileOutputStream fout = new FileOutputStream(sf);
      fout.write("testFileCleaned".getBytes());
      fout.close();
View Full Code Here


      assertTrue(vd.isByteArray());
   }

   public void testCreateFileStreamTransientValueData() throws Exception
   {
      FileCleaner testFileCleaner = new FileCleaner();
      try
      {
         byte[] buf = "0123456789".getBytes();
         File file = new File("target/testCreateFileStreamTransientValueData");
         if (file.exists())
            file.delete();
         FileOutputStream out = new FileOutputStream(file);
         out.write(buf);
         out.close();

         FileInputStream fs1 = new FileInputStream(file);

         SpoolConfig spoolConfig = SpoolConfig.getDefaultSpoolConfig();
         spoolConfig.maxBufferSize = 5;

         TransientValueData vd = new TransientValueData(0, fs1, null, spoolConfig);

         // spool to file
         InputStream fs2 = vd.getAsStream();
         assertEquals(10, vd.getLength());
         assertTrue(fs2 instanceof FileInputStream);

         // not the same object as new is is from spool file
         assertNotSame(fs1, fs2);
         // spooled to file so not a byte array
         assertFalse(vd.isByteArray());

         // next call return not the same object as well
         // (new stream every time)
         assertNotSame(vd.getAsStream(), fs2);
         assertEquals(10, vd.getLength());

         // gets as byte array
         assertEquals(10, vd.getAsByteArray().length);
         // but still spooled to file
         assertFalse(vd.isByteArray());

      }
      finally
      {
         testFileCleaner.halt();
      }

   }
View Full Code Here

      assertTrue(vd.getAsStream() instanceof FileInputStream);
   }

   public void testIfFinalizeRemovesTempFileStreamValueData() throws Exception
   {
      FileCleaner testFileCleaner = new FileCleaner(1000, true);
      try
      {
         byte[] buf = "0123456789".getBytes();
         File file = new File(new File("target"), "testIfFinalizeRemovesTempFileStreamValueData");
         SwapFile swapFile = SwapFile.get(new File("target"), "testIfFinalizeRemovesTempFileStreamValueData");
         //File file = new File("target/testIfFinalizeRemovesTempFileStreamValueData");
         //if (file.exists())
         //  file.delete();
         FileOutputStream out = new FileOutputStream(swapFile);
         out.write(buf);
         out.close();

         CleanableFilePersistedValueData vd =
            new CleanableFilePersistedValueData(0, swapFile, SpoolConfig.getDefaultSpoolConfig());
         assertTrue(file.exists());

         vd = null;
         swapFile = null;

         long purgeStartTime = System.currentTimeMillis();
         while (file.exists() && (System.currentTimeMillis() - purgeStartTime < 2 * 60 * 1000))
         {
            System.gc();
            try
            {
               Thread.sleep(500);
            }
            catch (InterruptedException e)
            {
            }
         }

         assertFalse(file.exists());
      }
      finally
      {
         testFileCleaner.halt();
      }
   }
View Full Code Here

   private int maxFufferSize = 10;

   public void testNewBinaryValue() throws Exception
   {
      FileCleaner testFileCleaner = new FileCleaner();

      try
      {
         byte[] buf = "012345678901234567890123456789".getBytes();
         File file = new File("target/testNewBinaryValue");
         if (file.exists())
            file.delete();
         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
         try
         {
            val.getString();
            fail("IllegalStateException should have been thrown");
         }
         catch (IllegalStateException e)
         {
         }
         // System.out.println(" >>>>>>>>STRING >>> "+);
      }
      finally
      {
         testFileCleaner.halt();
      }
   }
View Full Code Here

   @Override
   protected void setUp() throws Exception
   {
      super.setUp();

      cleaner = new FileCleaner(2000);

      rootDir = new File(new File("target"), "vs1");
      rootDir.mkdirs();

      new File(rootDir, FileValueStorage.TEMP_DIR_NAME).mkdirs();
View Full Code Here

         this.swapDirectory = new File(DEF_SWAPDIR);
      }
      if (!swapDirectory.exists())
         swapDirectory.mkdirs();

      this.swapCleaner = new FileCleaner(false);

      initDatabase();

      String suParam = null;
      boolean enableStorageUpdate = false;
View Full Code Here

      currentBackups = Collections.synchronizedSet(new HashSet<BackupChain>());

      currentRepositoryBackups = Collections.synchronizedSet(new HashSet<RepositoryBackupChain>());

      fileCleaner = new FileCleaner(10000);

      messages = new BackupMessagesLog(MESSAGES_MAXSIZE);

      scheduler = new BackupScheduler(this, messages);
View Full Code Here

   private FileCleaner fileCleaner;

   public IncrementalBackupJob()
   {
      fileCleaner = new FileCleaner(10000);
   }
View Full Code Here

      AccessManager accessManager) throws RepositoryConfigurationException, PathNotFoundException, RepositoryException
   {
      super(config, repConfig, dataManager, namespaceRegistry, locationFactory, nodeTypeManager, valueFactory,
         accessManager);

      this.fileCleaner = new FileCleaner();

      restoreDir = restorePath;

      String fullBackupPath = getFullBackupPath();
View Full Code Here

      this.dataManager = dataManager;

      this.namespaceRegistry = namespaceRegistry;
      this.locationFactory = locationFactory;

      this.fileCleaner = new FileCleaner(false); // cleaner should be started!
      this.maxBufferSize =
         config.getContainer().getParameterInteger(WorkspaceDataContainer.MAXBUFFERSIZE_PROP,
            WorkspaceDataContainer.DEF_MAXBUFFERSIZE);

      this.restorePath =
View Full Code Here

TOP

Related Classes of org.exoplatform.services.jcr.impl.util.io.FileCleaner

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.