当前位置: 首页>>代码示例>>Java>>正文


Java HashAlgorithm类代码示例

本文整理汇总了Java中org.sonatype.nexus.common.hash.HashAlgorithm的典型用法代码示例。如果您正苦于以下问题:Java HashAlgorithm类的具体用法?Java HashAlgorithm怎么用?Java HashAlgorithm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HashAlgorithm类属于org.sonatype.nexus.common.hash包,在下文中一共展示了HashAlgorithm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doPut

import org.sonatype.nexus.common.hash.HashAlgorithm; //导入依赖的package包/类
@TransactionalStoreBlob
protected Content doPut(final MavenPath path,
                        final Path sourceFile,
                        final String contentType,
                        final AttributesMap contentAttributes,
                        final Map<HashAlgorithm, HashCode> hashes,
                        final long size)
    throws IOException
{
  final StorageTx tx = UnitOfWork.currentTx();

  final AssetBlob assetBlob = tx.createBlob(
      path.getPath(),
      sourceFile,
      hashes,
      null,
      contentType,
      size
  );

  return doPutAssetBlob(path, contentAttributes, tx, assetBlob);
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:23,代码来源:MavenFacetImpl.java

示例2: write

import org.sonatype.nexus.common.hash.HashAlgorithm; //导入依赖的package包/类
/**
 * Writes passed in metadata as XML.
 */
public static void write(final Repository repository, final MavenPath mavenPath, final Metadata metadata)
    throws IOException
{
  MavenFacet mavenFacet = repository.facet(MavenFacet.class);
  final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  MavenModels.writeMetadata(buffer, metadata);
  mavenFacet.put(mavenPath, new BytesPayload(buffer.toByteArray(),
      MavenMimeRulesSource.METADATA_TYPE));
  final Map<HashAlgorithm, HashCode> hashCodes = mavenFacet.get(mavenPath).getAttributes()
      .require(Content.CONTENT_HASH_CODES_MAP, Content.T_CONTENT_HASH_CODES_MAP);
  checkState(hashCodes != null, "hashCodes");
  for (HashType hashType : HashType.values()) {
    MavenPath checksumPath = mavenPath.hash(hashType);
    HashCode hashCode = hashCodes.get(hashType.getHashAlgorithm());
    checkState(hashCode != null, "hashCode: type=%s", hashType);
    mavenFacet.put(checksumPath, new StringPayload(hashCode.toString(), Constants.CHECKSUM_CONTENT_TYPE));
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:22,代码来源:MetadataUtils.java

示例3: putWithHashes

import org.sonatype.nexus.common.hash.HashAlgorithm; //导入依赖的package包/类
/**
 * Performs a {@link MavenFacet#put(MavenPath, Payload)} for passed in {@link Content} and it's hashes too. Returns
 * the put content.
 */
public static Content putWithHashes(final MavenFacet mavenFacet,
    final MavenPath mavenPath,
    final Content content) throws IOException
{
  final Map<HashAlgorithm, HashCode> hashCodes = content.getAttributes().require(
      Content.CONTENT_HASH_CODES_MAP, Content.T_CONTENT_HASH_CODES_MAP);
  final DateTime now = content.getAttributes().require(Content.CONTENT_LAST_MODIFIED, DateTime.class);
  Content result = mavenFacet.put(mavenPath, content);
  for (HashType hashType : HashType.values()) {
    final HashCode hashCode = hashCodes.get(hashType.getHashAlgorithm());
    if (hashCode != null) {
      final Content hashContent = new Content(
          new StringPayload(hashCode.toString(), Constants.CHECKSUM_CONTENT_TYPE));
      hashContent.getAttributes().set(Content.CONTENT_LAST_MODIFIED, now);
      mavenFacet.put(mavenPath.hash(hashType), hashContent);
    }
  }
  return result;
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:24,代码来源:MavenFacetUtils.java

示例4: extractFromAsset

import org.sonatype.nexus.common.hash.HashAlgorithm; //导入依赖的package包/类
/**
 * Extracts non-format specific content attributes into the passed in {@link AttributesMap} (usually originating from
 * {@link Content#getAttributes()}) from passed in {@link Asset} and format required hashes.
 */
public static void extractFromAsset(final Asset asset,
                                    final Iterable<HashAlgorithm> hashAlgorithms,
                                    final AttributesMap contentAttributes)
{
  checkNotNull(asset);
  checkNotNull(hashAlgorithms);
  final NestedAttributesMap assetAttributes = asset.attributes().child(CONTENT);
  final DateTime lastModified = toDateTime(assetAttributes.get(P_LAST_MODIFIED, Date.class));
  final String etag = assetAttributes.get(P_ETAG, String.class);

  final Map<HashAlgorithm, HashCode> checksums = asset.getChecksums(hashAlgorithms);

  contentAttributes.set(Asset.class, asset);
  contentAttributes.set(Content.CONTENT_LAST_MODIFIED, lastModified);
  contentAttributes.set(Content.CONTENT_ETAG, etag);
  contentAttributes.set(Content.CONTENT_HASH_CODES_MAP, checksums);
  contentAttributes.set(CacheInfo.class, CacheInfo.extractFromAsset(asset));
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:23,代码来源:Content.java

示例5: createBlob

import org.sonatype.nexus.common.hash.HashAlgorithm; //导入依赖的package包/类
@Override
@Guarded(by = ACTIVE)
public AssetBlob createBlob(final String blobName,
                            final Supplier<InputStream> streamSupplier,
                            final Iterable<HashAlgorithm> hashAlgorithms,
                            @Nullable final Map<String, String> headers,
                            @Nullable final String declaredContentType,
                            final boolean skipContentVerification) throws IOException
{
  checkNotNull(blobName);
  checkNotNull(streamSupplier);
  checkNotNull(hashAlgorithms);

  if (!writePolicy.checkCreateAllowed()) {
    throw new IllegalOperationException("Repository is read only: " + repositoryName);
  }

  Map<String, String> storageHeadersMap = buildStorageHeaders(blobName, streamSupplier, headers, declaredContentType,
      skipContentVerification);
  return blobTx.create(
      streamSupplier.get(),
      storageHeadersMap,
      hashAlgorithms,
      storageHeadersMap.get(BlobStore.CONTENT_TYPE_HEADER)
  );
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:27,代码来源:StorageTxImpl.java

示例6: createAssetBlob

import org.sonatype.nexus.common.hash.HashAlgorithm; //导入依赖的package包/类
private AssetBlob createAssetBlob(final Function<BlobStore, Blob> blobFunction,
                                  final Map<HashAlgorithm, HashCode> hashes,
                                  final boolean hashesVerified,
                                  final String contentType)
{
  AssetBlob assetBlob = new AssetBlob(
      nodeAccess,
      blobStore,
      blobFunction,
      contentType,
      hashes,
      hashesVerified);

  newlyCreatedBlobs.add(assetBlob);
  return assetBlob;
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:17,代码来源:BlobTx.java

示例7: setup

import org.sonatype.nexus.common.hash.HashAlgorithm; //导入依赖的package包/类
@Before
public void setup() {
  Map<String,Object> checksum = Maps.newHashMap(ImmutableMap.of(HashAlgorithm.SHA1.name(), "87acec17cd9dcd20a716cc2cf67417b71c8a7016"));

  when(assetOne.name()).thenReturn("nameOne");
  when(assetOne.getEntityMetadata()).thenReturn(assetOneEntityMetadata);
  when(assetOne.attributes()).thenReturn(new NestedAttributesMap(Asset.CHECKSUM, checksum));

  when(assetOneORID.toString()).thenReturn("assetOneORID");

  when(assetOneEntityMetadata.getId()).thenReturn(assetOneEntityId);
  when(assetOneEntityId.getValue()).thenReturn("assetOne");

  when(repository.getName()).thenReturn("maven-releases");
  when(repository.getUrl()).thenReturn("http://localhost:8081/repository/maven-releases");
  when(repository.getFormat()).thenReturn(new Format("maven2") {});
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:18,代码来源:AssetXOTest.java

示例8: buildIndexSection

import org.sonatype.nexus.common.hash.HashAlgorithm; //导入依赖的package包/类
private String buildIndexSection(ControlFile cf, long size, Map<HashAlgorithm, HashCode> hashes, String assetPath) {
  Paragraph modified = cf.getParagraphs().get(0)
      .withFields(Arrays.asList(
          new ControlFile.ControlField("Filename", assetPath),
          new ControlFile.ControlField("Size", Long.toString(size)),
          new ControlFile.ControlField("MD5Sum", hashes.get(MD5).toString()),
          new ControlFile.ControlField("SHA1", hashes.get(SHA1).toString()),
          new ControlFile.ControlField("SHA256", hashes.get(SHA256).toString())));
  return modified.toString();
}
 
开发者ID:sonatype-nexus-community,项目名称:nexus-repository-apt,代码行数:11,代码来源:AptHostedFacet.java

示例9: addSignatureItem

import org.sonatype.nexus.common.hash.HashAlgorithm; //导入依赖的package包/类
private void addSignatureItem(StringBuilder builder, HashAlgorithm algo, Content content, String filename) {
  Map<HashAlgorithm, HashCode> hashMap = content.getAttributes().get(Content.CONTENT_HASH_CODES_MAP,
      Content.T_CONTENT_HASH_CODES_MAP);
  builder.append("\n ");
  builder.append(hashMap.get(algo).toString());
  builder.append(" ");
  builder.append(content.getSize());
  builder.append(" ");
  builder.append(filename);
}
 
开发者ID:sonatype-nexus-community,项目名称:nexus-repository-apt,代码行数:11,代码来源:AptHostedFacet.java

示例10: put

import org.sonatype.nexus.common.hash.HashAlgorithm; //导入依赖的package包/类
@Override
public Content put(final MavenPath path,
                   final Path sourceFile,
                   final String contentType,
                   final AttributesMap contentAttributes,
                   final Map<HashAlgorithm, HashCode> hashes,
                   final long size)
    throws IOException
{
  log.debug("PUT {} : {}", getRepository().getName(), path.getPath());

  return doPut(path, sourceFile, contentType, contentAttributes, hashes, size);
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:14,代码来源:MavenFacetImpl.java

示例11: mayAddETag

import org.sonatype.nexus.common.hash.HashAlgorithm; //导入依赖的package包/类
/**
 * Adds {@link Content#CONTENT_ETAG} content attribute if not present. In case of hosted repositories, this is safe
 * and even good thing to do, as the content is hosted here only and NX is content authority.
 */
public static void mayAddETag(final Content content) {
  if (content.getAttributes().contains(Content.CONTENT_ETAG)) {
    return;
  }
  Map<HashAlgorithm, HashCode> hashCodes = content.getAttributes()
      .require(Content.CONTENT_HASH_CODES_MAP, Content.T_CONTENT_HASH_CODES_MAP);
  HashCode sha1HashCode = hashCodes.get(HashAlgorithm.SHA1);
  if (sha1HashCode != null) {
    content.getAttributes().set(Content.CONTENT_ETAG, "{SHA1{" + sha1HashCode + "}}");
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:16,代码来源:MavenFacetUtils.java

示例12: doRestore

import org.sonatype.nexus.common.hash.HashAlgorithm; //导入依赖的package包/类
private void doRestore(StorageFacet storageFacet, RestoreBlobData blobData, T restoreData, boolean isDryRun) {
  String logPrefix = isDryRun ? dryRunPrefix.get() : "";
  String path = getAssetPath(restoreData);
  String blobStoreName = blobData.getBlobStoreName();
  String repoName = blobData.getRepository().getName();
  String blobName = blobData.getBlobName();
  Blob blob = blobData.getBlob();

  UnitOfWork.begin(storageFacet.txSupplier());
  try {
    if (assetExists(restoreData)) {
      log.debug(
          "Skipping as asset already exists, blob store: {}, repository: {}, path: {}, blob name: {}, blob id: {}",
          blobStoreName, repoName, path, blobName, blob.getId());
      return;
    }

    if (!isDryRun) {
      List<HashAlgorithm> hashTypes = getHashAlgorithms();

      AssetBlob assetBlob = new AssetBlob(nodeAccess, blobStoreManager.get(blobStoreName), blobStore -> blob,
          blobData.getProperty(HEADER_PREFIX + CONTENT_TYPE_HEADER),
          hash(hashTypes, blob.getInputStream()), true);

      createAssetFromBlob(assetBlob, restoreData);
    }

    log.info("{}Restored asset, blob store: {}, repository: {}, path: {}, blob name: {}, blob id: {}",
        logPrefix, blobStoreName, repoName, path, blobName, blob.getId());
  }
  catch (IOException e) {
    log.error("Error while restoring asset: blob store: {}, repository: {}, path: {}, blob name: {}, blob id: {}",
        blobStoreName, repoName, path, blobName, blob.getId(), e);
  }
  finally {
    UnitOfWork.end();
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:39,代码来源:BaseRestoreBlobStrategy.java

示例13: testCorrectChecksums

import org.sonatype.nexus.common.hash.HashAlgorithm; //导入依赖的package包/类
@Test
public void testCorrectChecksums() throws Exception {
  Map<HashAlgorithm, HashCode> expectedHashes = Maps.newHashMap();
  expectedHashes.put(HashAlgorithm.MD5, HashAlgorithm.MD5.function().hashBytes(blobBytes));
  expectedHashes.put(HashAlgorithm.SHA1, HashAlgorithm.SHA1.function().hashBytes(blobBytes));
  ArgumentCaptor<AssetBlob> assetBlobCaptor = ArgumentCaptor.forClass(AssetBlob.class);

  underTest.restore(properties, blob, "test", false);
  verify(mavenFacet).get(mavenPath);
  verify(mavenFacet).put(eq(mavenPath), assetBlobCaptor.capture(), eq(null));

  assertEquals("asset hashes do not match blob", expectedHashes, assetBlobCaptor.getValue().getHashes());
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:14,代码来源:MavenRestoreBlobStrategyTest.java

示例14: createTempBlob

import org.sonatype.nexus.common.hash.HashAlgorithm; //导入依赖的package包/类
@Override
public TempBlob createTempBlob(final InputStream inputStream, final Iterable<HashAlgorithm> hashAlgorithms) {
  BlobStore blobStore = checkNotNull(blobStoreManager.get(config.blobStoreName));
  MultiHashingInputStream hashingStream = new MultiHashingInputStream(hashAlgorithms, inputStream);
  Blob blob = blobStore.create(hashingStream,
      ImmutableMap.of(
          BlobStore.BLOB_NAME_HEADER, "temp",
          BlobStore.CREATED_BY_HEADER, createdBy(),
          BlobStore.CREATED_BY_IP_HEADER, createdByIp(),
          BlobStore.TEMPORARY_BLOB_HEADER, ""));
  return new TempBlob(blob, hashingStream.hashes(), true, blobStore);
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:13,代码来源:StorageFacetImpl.java

示例15: checksumExists

import org.sonatype.nexus.common.hash.HashAlgorithm; //导入依赖的package包/类
/**
 * Returns {@code true} when at least one incoming hash has the same algorithm as an existing checksum.
 */
private boolean checksumExists(final NestedAttributesMap checksums, final AssetBlob assetBlob) {
  if (!checksums.isEmpty()) {
    for (HashAlgorithm algorithm : assetBlob.getHashes().keySet()) {
      if (checksums.contains(algorithm.name())) {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:14,代码来源:StorageTxImpl.java


注:本文中的org.sonatype.nexus.common.hash.HashAlgorithm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。