it.tidalwave.integritychecker.fingerprint.Fingerprint Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of it-tidalwave-integritychecker Show documentation
Show all versions of it-tidalwave-integritychecker Show documentation
This module provides the core function for checking the integrity of files.
/*
* #%L
* *********************************************************************************************************************
*
* SolidBlue - open source safe data
* http://solidblue.tidalwave.it - hg clone https://bitbucket.org/tidalwave/solidblue-src
* %%
* Copyright (C) 2011 - 2013 Tidalwave s.a.s. (http://tidalwave.it)
* %%
* *********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* *********************************************************************************************************************
*
* $Id$
*
* *********************************************************************************************************************
* #L%
*/
package it.tidalwave.integritychecker.fingerprint;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import java.io.Serializable;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
/***********************************************************************************************************************
*
* A fingerprint computed with a given algorithm.
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
@Immutable @RequiredArgsConstructor @ToString @EqualsAndHashCode @Getter
public class Fingerprint implements Serializable
{
@Nonnull
private final String type;
@Nonnull
private final String value;
public Fingerprint (final @Nonnull String algorithm, final @Nonnull byte[] digest)
{
this(algorithm, toString(digest));
}
@Nonnull
private static String toString (final @Nonnull byte[] bytes)
{
final StringBuilder builder = new StringBuilder();
for (final byte b : bytes)
{
final int value = b & 0xff;
builder.append(Integer.toHexString(value >>> 4)).append(Integer.toHexString(value & 0x0f));
}
return builder.toString();
}
}