本文整理匯總了Java中javax.xml.bind.annotation.adapters.HexBinaryAdapter類的典型用法代碼示例。如果您正苦於以下問題:Java HexBinaryAdapter類的具體用法?Java HexBinaryAdapter怎麽用?Java HexBinaryAdapter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HexBinaryAdapter類屬於javax.xml.bind.annotation.adapters包,在下文中一共展示了HexBinaryAdapter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createSha1
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; //導入依賴的package包/類
public String createSha1(File file) throws TechnicalException {
try (InputStream fis = new FileInputStream(file);) {
MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
int n = 0;
byte[] buffer = new byte[8192];
while (n != -1) {
n = fis.read(buffer);
if (n > 0) {
sha1.update(buffer, 0, n);
}
}
return new HexBinaryAdapter().marshal(sha1.digest());
} catch (NoSuchAlgorithmException | IOException e) {
throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_CHECKSUM_IO_EXCEPTION), e);
}
}
示例2: inviteUser
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; //導入依賴的package包/類
private void inviteUser(GameProfile profile)
{
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
Gson gson = new Gson();
UserListWhitelist whitelistedPlayers = server.getConfigurationManager().func_152599_k();
final ArrayList<String> tempHash = new ArrayList<String>();
String name = profile.getName().toLowerCase();
try
{
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(whitelistedPlayers.func_152706_a(name).getId().toString().getBytes(Charset.forName("UTF-8")));
tempHash.add((new HexBinaryAdapter()).marshal(hash));
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
CreeperHostServer.InviteClass invite = new CreeperHostServer.InviteClass();
invite.hash = tempHash;
invite.id = CreeperHostServer.updateID;
Util.putWebResponse("https://api.creeper.host/serverlist/invite", gson.toJson(invite), true, true);
}
示例3: removeUser
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; //導入依賴的package包/類
private void removeUser(GameProfile profile)
{
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
Gson gson = new Gson();
final ArrayList<String> tempHash = new ArrayList<String>();
try
{
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(profile.getId().toString().getBytes(Charset.forName("UTF-8")));
tempHash.add((new HexBinaryAdapter()).marshal(hash));
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
CreeperHostServer.InviteClass invite = new CreeperHostServer.InviteClass();
invite.hash = tempHash;
invite.id = CreeperHostServer.updateID;
CreeperHostServer.logger.debug("Sending " + gson.toJson(invite) + " to revoke endpoint");
String resp = Util.putWebResponse("https://api.creeper.host/serverlist/revokeinvite", gson.toJson(invite), true, true);
CreeperHostServer.logger.debug("Response from revoke endpoint " + resp);
}
示例4: getPlayerHash
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; //導入依賴的package包/類
public static String getPlayerHash(UUID uuid)
{
if (hashCache.containsKey(uuid))
return hashCache.get(uuid);
String playerHash;
try
{
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(uuid.toString().getBytes(Charset.forName("UTF-8")));
playerHash = (new HexBinaryAdapter()).marshal(hash);
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
return null;
}
hashCache.put(uuid, playerHash);
return playerHash;
}
示例5: hash
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; //導入依賴的package包/類
@ApiMethod
@Comment(value = "Hash the bytes with the given algorithm")
public static String hash(byte[] byteArr, String algorithm)
{
try
{
MessageDigest digest = MessageDigest.getInstance(algorithm);
digest.update(byteArr);
byte[] bytes = digest.digest();
String hex = (new HexBinaryAdapter()).marshal(bytes);
return hex;
}
catch (Exception ex)
{
Lang.rethrow(ex);
}
return null;
}
示例6: calcSHA
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; //導入依賴的package包/類
public static String calcSHA(File file) throws Exception {
MessageDigest sha1 = MessageDigest.getInstance("SHA-512");
InputStream input = new FileInputStream(file);
try {
byte[] buffer = new byte[8192];
int len = input.read(buffer);
while (len != -1) {
sha1.update(buffer, 0, len);
len = input.read(buffer);
}
input.close();
return new HexBinaryAdapter().marshal(sha1.digest());
} catch (Exception ex) {
return "";
}
}
示例7: main
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
final byte[] bytes2 = Base64.getDecoder().decode("YnsLfVSN");
System.out.println(new HexBinaryAdapter().marshal(bytes2));
if(true) {
return;
}
String filename = "/Users/esinev/Library/Preferences/IdeaIC15/scratches/docker-create-endpoint.txt";
LineNumberReader reader = new LineNumberReader(new FileReader(filename));
String line;
while (( line = reader.readLine()) != null) {
// System.out.println(line);
if(line.length() >= 50 && line.charAt(48) == ' ' && line.charAt(49) == ' ') {
String hex = line.substring(0, 49);
final byte[] bytes = new HexBinaryAdapter().unmarshal(hex.replace(" ", ""));
String value = new String(bytes);
System.out.print(value);
// line = line.substring(50);
} else {
System.out.println(line);
}
// System.out.println(line);
}
}
示例8: testUUIDConverter
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; //導入依賴的package包/類
@Test
public void testUUIDConverter() throws ConverterException {
UUID uuid = UUID.randomUUID();
OracleQuirks orclQuirks = new OracleQuirks();
Converter<UUID> uuidConverter = new OracleUUIDConverter();
byte[] rawUuid = (byte[])uuidConverter.toDatabaseParam(uuid);
UUID reconvertedUuid = uuidConverter.convert(rawUuid);
assertEquals(uuid, reconvertedUuid);
// convert bytes to hex and put hyphens into the string to recreate the UUID string representation, just to be
// sure everything is done correct.
String hex = new HexBinaryAdapter().marshal(rawUuid);
String hexUuid = String.format("%s-%s-%s-%s-%s",
hex.substring(0,8),
hex.substring(8,12),
hex.substring(12, 16),
hex.substring(16, 20),
hex.substring(20)).toLowerCase();
assertEquals(uuid.toString(), hexUuid);
}
示例9: sha2OfBigger
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; //導入依賴的package包/類
private String sha2OfBigger(File f) {
try (FileChannel ch = new RandomAccessFile(f, "r").getChannel()) {
int size = (int) Math.min(f.length(), Integer.MAX_VALUE);
MappedByteBuffer byteBuffer // 2G
= ch.map(FileChannel.MapMode.READ_ONLY, 0, size);
MessageDigest sha2 = MessageDigest.getInstance("SHA-256");
long offset = 0;
byte[] array = new byte[Integer.MAX_VALUE >> 2];
while (size != 0) {
while (byteBuffer.remaining() > 0) {
int numInArray = Math.min(array.length, byteBuffer.remaining());
byteBuffer.get(array, 0, numInArray);
sha2.update(array, 0, numInArray);
}
offset += size;
size = (int) Math.min(Integer.MAX_VALUE, f.length() - offset);
byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, offset, size);
}
return new HexBinaryAdapter().marshal(sha2.digest());
} catch (IOException | NoSuchAlgorithmException e) {
e.printStackTrace();
return "\\";
}
}
示例10: sha2Of
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; //導入依賴的package包/類
private String sha2Of(File file) {
if (file.length() > Integer.MAX_VALUE >> 2) {
return sha2OfBigger(file);
}
try (FileChannel ch = new FileInputStream(file).getChannel()) {
byte[] arry = new byte[1024 * 8];
ByteBuffer byteBuffer = ByteBuffer.wrap(arry);
int size = ch.read(byteBuffer);
MessageDigest sha2 = MessageDigest.getInstance("SHA-256");
while (size != -1) {
sha2.update(arry, 0, size);
byteBuffer.rewind();
size = ch.read(byteBuffer);
}
return new HexBinaryAdapter().marshal(sha2.digest());
} catch (IOException | NoSuchAlgorithmException e) {
e.printStackTrace();
return "\\";
}
}
示例11: calcSHA1
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; //導入依賴的package包/類
private static String calcSHA1(File file) throws
IOException, NoSuchAlgorithmException {
MessageDigest sha1 = MessageDigest.getInstance("SHA-1"); // todo algorithm here??
try (InputStream input = new FileInputStream(file)) {
byte[] buffer = new byte[1024 * 8];
int len = input.read(buffer);
while (len != -1) {
sha1.update(buffer, 0, len);
len = input.read(buffer);
}
return new HexBinaryAdapter().marshal(sha1.digest());
}
}
示例12: calculateSha1
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; //導入依賴的package包/類
private String calculateSha1(File file) throws MojoExecutionException {
InputStream input = null;
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
input = new FileInputStream(file);
byte[] buffer = new byte[8192];
int len;
while ((len = input.read(buffer)) != -1) {
messageDigest.update(buffer, 0, len);
}
return new HexBinaryAdapter().marshal(messageDigest.digest());
} catch (Exception exception) {
throw new MojoExecutionException("Could not create SHA1 of file [" + file + "]");
} finally {
IOUtils.closeQuietly(input);
}
}
示例13: calculateSha1
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; //導入依賴的package包/類
/**
* Calculate and return the sha1 sum of an input stream
*
* @param in the input stream to calculate the sha1 sum of
*
* @return the sha1 sum
*
* @throws IOException if there was an error calculating the sha1 sum
*/
public static String calculateSha1(InputStream in) throws IOException {
MessageDigest messageDigest;
InputStream inputStream = null;
try {
messageDigest = MessageDigest.getInstance("SHA-1");
inputStream = new BufferedInputStream(in);
byte[] buffer = new byte[8192];
int len = inputStream.read(buffer);
while (len != -1) {
messageDigest.update(buffer, 0, len);
len = inputStream.read(buffer);
}
return(new HexBinaryAdapter().marshal(messageDigest.digest()));
} catch (NoSuchAlgorithmException ex) {
throw new IOException(ex);
} finally {
IOUtils.closeQuietly(inputStream);
}
}
示例14: testSigning
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; //導入依賴的package包/類
@Test
public void testSigning() throws AddressFormatException {
NetworkParameters netParams = TestNet3Params.get();
HexBinaryAdapter adapter = new HexBinaryAdapter();
Context context = Context.getOrCreate(netParams);
byte[] bx = adapter.unmarshal("0100000001bd5ee90ffe5eedd67c09c3bb348dd7dc1308800eb221b1c92dda651010519ba3010000006a4730440220467868c0b2ed001a915cca5269b928698bee8aba4fe454e1d775070d9e4041cb02205d1c979dbc75e5dc656c4e9d5969d716a383797bd5ad5df79a13d0d6e3f51ccb012102403adb7674f25212bc8cf4a97797154a4980c60e9f328c90300b71a8a04389c7ffffffff024088db60000000001976a914990628d3670f439a5f9e0dfa6492b8bbf3b3fa1b88ac76cf6edd050000001976a914b679378d01ee7203a454bca2ad25698ef23a056388ac00000000");
org.bitcoinj.core.Transaction testbx = new org.bitcoinj.core.Transaction(netParams, bx);
org.bitcoinj.core.Transaction tx = new org.bitcoinj.core.Transaction(netParams);
tx.addOutput(org.bitcoinj.core.Coin.SATOSHI.multiply(testbx.getOutput(0).getValue().value - 50000l), new Address(netParams, "mobDb19geJ66kkQnsSYvN9PNEKNDiNBHEp"));
System.out.println(testbx.getOutput(0));
tx.addInput(testbx.getOutput(0));
String seckey = "3EC95EBFEDCF77373BABA0DE345A0962E51344CD2D0C8DBDF93AEFD0B66BE240";
byte[] privkey = Hex.decode(seckey);
ECKey ecPriv = ECKey.fromPrivate(privkey);
Sha256Hash hash2 = tx.hashForSignature(0, testbx.getOutput(0).getScriptPubKey().getProgram(), Transaction.SigHash.ALL, false);
ECKey.ECDSASignature ecSig = ecPriv.sign(hash2);
TransactionSignature txSig = new TransactionSignature(ecSig, Transaction.SigHash.ALL, false);
Script inputScript = ScriptBuilder.createInputScript(txSig, ECKey.fromPublicOnly(ecPriv.getPubKey()));
tx.getInput(0).setScriptSig(inputScript);
String hexBin = DatatypeConverter.printHexBinary(tx.bitcoinSerialize());
System.out.println(hexBin);
tx.getInput(0).verify(testbx.getOutput(0));
// SUCCESSFULLY BROADCAST WOO!
}
示例15: swaAttachment
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; //導入依賴的package包/類
/**
* This method passes an SWA attachment as a request
* and expects an SWA attachment as a response.
* Note that the body content in both cases is empty.
* (See the wsdl)
* @param attachment (swa)
* @return attachment (swa)
*/
@WebMethod(operationName="swaAttachment", action="swaAttachment")
@XmlJavaTypeAdapter(HexBinaryAdapter.class)
@WebResult(name = "jpegImageResponse", targetNamespace = "", partName = "jpegImageResponse")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public byte[] swaAttachment(
@XmlJavaTypeAdapter(HexBinaryAdapter.class)
@WebParam(name = "jpegImageRequest", targetNamespace = "", partName = "jpegImageRequest")
byte[] attachment) {
if (attachment == null || attachment.length == 0){
throw new RuntimeException("Received empty attachment");
} else {
// Change the first three characters and return the attachment
attachment[0] = 'S';
attachment[1] = 'W';
attachment[2] = 'A';
}
return attachment;
}