Java ReentrantLock xor(byte[] a, byte[] b)

Here you can find the source of xor(byte[] a, byte[] b)

Description

xor

License

Open Source License

Declaration

public static final byte[] xor(byte[] a, byte[] b) 

Method Source Code


//package com.java2s;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Main {
    private static final Lock lock = new ReentrantLock();

    public static final byte[] xor(byte[] a, byte[] b) {

        lock.lock();//  w  w  w  .  j a va 2 s  .c om
        try {
            if (a.length != b.length)
                throw new RuntimeException("inputs must be equal lengths");

            byte[] result = new byte[a.length];
            for (int i = 0; i < a.length; i++) {
                result[i] = (byte) (0xff & ((int) a[i]) ^ ((int) b[i]));
            }

            return result;

        } finally {
            lock.unlock();
        }
    }
}

Related

  1. readSyncLock(String id)
  2. removeJavaStdLoggerHandlers()
  3. runConcurrent(long startGapTime, Runnable... tasks)
  4. runUnderLock(ReentrantLock lock, Runnable runnable)
  5. toLazyCollection(Stream stream)