Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.MetaFileSmall


    KeyPair metaFileKeys = node.getFileKeys();
    if (originalFile.isFile()) {
      MetaFile metaFile = UseCaseTestUtil.getMetaFile(client, metaFileKeys);
      Assert.assertNotNull(metaFile);
      Assert.assertTrue(metaFile instanceof MetaFileSmall);
      MetaFileSmall metaFileSmall = (MetaFileSmall) metaFile;

      // get the meta file with the keys (decrypt it)
      Assert.assertEquals(1, metaFileSmall.getVersions().size());
      Assert.assertEquals(expectedChunks, metaFileSmall.getVersions().get(0).getMetaChunks().size());
    }

    // verify the file (should have been downloaded automatically during the notification)
    Path relative = uploaderRoot.toPath().relativize(originalFile.toPath());
    File file = new File(downloaderRoot, relative.toString());
View Full Code Here


    metaChunks2.add(new MetaChunk(NetworkTestUtil.randomString(), NetworkTestUtil.randomString()
        .getBytes(), 2));
    List<FileVersion> fileVersions = new ArrayList<FileVersion>();
    fileVersions.add(new FileVersion(0, 123, System.currentTimeMillis(), metaChunks1));
    fileVersions.add(new FileVersion(1, 123, System.currentTimeMillis(), metaChunks2));
    MetaFileSmall metaFileSmall = new MetaFileSmall(metaFileEncryptionKeys.getPublic(), fileVersions,
        chunkEncryptionKeys);
    // encrypt the meta file
    HybridEncryptedContent encryptedMetaFile = H2HEncryptionUtil.encryptHybrid(metaFileSmall,
        metaFileEncryptionKeys.getPublic());
    encryptedMetaFile.generateVersionKey();

    // initialize put
    Parameters parameters = new Parameters()
        .setLocationKey(H2HEncryptionUtil.key2String(metaFileSmall.getId()))
        .setContentKey(H2HConstants.META_FILE).setVersionKey(encryptedMetaFile.getVersionKey())
        .setProtectionKeys(protectionKeysOld).setData(encryptedMetaFile);
    // indicate to generate hash
    parameters.setHashFlag(true);
    // put encrypted meta file into network
View Full Code Here

    List<MetaChunk> metaChunks = new ArrayList<MetaChunk>();
    MetaFile metaFile = context.consumeMetaFile();

    if (metaFile.isSmall()) {
      MetaFileSmall metaSmall = (MetaFileSmall) metaFile;
      // TODO rather delete file by file than all chunks mixed
      for (FileVersion version : metaSmall.getVersions()) {
        metaChunks.addAll(version.getMetaChunks());
      }
    }

    // process composition
View Full Code Here

    } else if (!(metaFile.isSmall())) {
      logger.debug("No need to update any chunks for a large meta file");
      return;
    }

    MetaFileSmall metaFileSmall = (MetaFileSmall) metaFile;
    logger.debug("Initialize updating all chunks for file '{}' in a shared folder.",
        context.getFileName());
    int counter = 0;
    for (FileVersion version : metaFileSmall.getVersions()) {
      for (MetaChunk metaChunk : version.getMetaChunks()) {
        // each chunk gets an own context
        ChunkPKUpdateContext chunkContext = new ChunkPKUpdateContext(
            context.consumeOldProtectionKeys(), context.consumeNewProtectionKeys(), metaChunk);
View Full Code Here

      // create new meta file with new version
      FileVersion version = new FileVersion(0, FileUtil.getFileSize(file), System.currentTimeMillis(),
          context.getMetaChunks());
      List<FileVersion> versions = new ArrayList<FileVersion>(1);
      versions.add(version);
      metaFile = new MetaFileSmall(context.generateOrGetMetaKeys().getPublic(), versions,
          context.consumeChunkKeys());

    }
    context.provideMetaFile(metaFile);
  }
View Full Code Here

      throw new ProcessExecutionException("Meta document not found.");
    } else if (!metaFile.isSmall()) {
      throw new ProcessExecutionException("Meta document is not a small meta file.");
    }

    MetaFileSmall metaFileSmall = (MetaFileSmall) metaFile;
    // cast the versions to the public interface
    List<IFileVersion> versions = new ArrayList<IFileVersion>();
    for (FileVersion version : metaFileSmall.getVersions()) {
      if (metaFileSmall.getNewestVersion().equals(version)) {
        // skip newest version since it's not worth to restore it
        continue;
      }

      versions.add(version);
    }

    logger.debug(
        "Start with the selection of the version by the user. The user has choice between {} versions.",
        versions.size());
    IFileVersion selected = selector.selectVersion(versions);
    if (selected == null) {
      throw new ProcessExecutionException("Selected file version is null.");
    }

    // find the selected version
    FileVersion selectedVersion = null;
    for (FileVersion version : metaFileSmall.getVersions()) {
      if (version.getIndex() == selected.getIndex()) {
        selectedVersion = version;
        break;
      }
    }

    // check if the developer returned an invalid index
    if (selectedVersion == null) {
      throw new ProcessExecutionException("Invalid version index selected.");
    }

    logger.debug("Selected version {} where {} is newest.", selected.getIndex(), metaFileSmall
        .getNewestVersion().getIndex());

    // 1. download the file with new name <filename>_<date>
    // 2. add the file with an AddFileProcess (which also notifies other clients)
    try {
      // find the node at the user profile
      UserProfileManager profileManager = networkManager.getSession().getProfileManager();
      UserProfile userProfile = profileManager.getUserProfile(getID(), false);
      Index selectedNode = userProfile.getFileById(metaFileSmall.getId());
      if (selectedNode == null) {
        throw new Hive2HiveException("File node not found");
      }

      // ask the user for the new file name
View Full Code Here

TOP

Related Classes of org.hive2hive.core.model.MetaFileSmall

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.