Example usage for java.util Arrays copyOf

List of usage examples for java.util Arrays copyOf

Introduction

In this page you can find the example usage for java.util Arrays copyOf.

Prototype

public static boolean[] copyOf(boolean[] original, int newLength) 

Source Link

Document

Copies the specified array, truncating or padding with false (if necessary) so the copy has the specified length.

Usage

From source file:Clases.cCifrado.java

public String Desencriptar(String textoEncriptado) {

    String secretKey = "MARSOFT"; //llave para encriptar datos
    String base64EncryptedString = "";

    try {/*from   w w  w . ja v a  2 s .  c om*/
        byte[] message = Base64.decodeBase64(textoEncriptado.getBytes("utf-8"));
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8"));
        byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
        SecretKey key = new SecretKeySpec(keyBytes, "DESede");

        Cipher decipher = Cipher.getInstance("DESede");
        decipher.init(Cipher.DECRYPT_MODE, key);

        byte[] plainText = decipher.doFinal(message);

        base64EncryptedString = new String(plainText, "UTF-8");

    } catch (Exception ex) {
    }
    return base64EncryptedString;
}

From source file:acromusashi.stream.ml.anomaly.lof.entity.LofPoint.java

/**
 * ?DeepCopy??//from  w w w  . j a  va  2 s .  c  o  m
 * 
 * @return ?DeepCopy
 */
public LofPoint deepCopy() {
    LofPoint result = new LofPoint();
    result.setDataId(this.dataId);
    result.setkDistance(this.kDistance);

    double[] copiedArray = Arrays.copyOf(this.dataPoint, this.dataPoint.length);
    result.setDataPoint(copiedArray);

    List<String> copiedList = new ArrayList<>();
    if (this.kDistanceNeighbor != null) {
        copiedList.addAll(this.kDistanceNeighbor);
    }

    result.setkDistanceNeighbor(copiedList);
    result.setLrd(this.lrd);
    return result;
}

From source file:uk.co.caprica.brue.core.domain.bridge.GroupAction.java

@JsonCreator
public GroupAction(@JsonProperty("on") Boolean on, @JsonProperty("bri") Integer brightness,
        @JsonProperty("hue") Integer hue, @JsonProperty("sat") Integer saturation,
        @JsonProperty("ct") Integer ct, @JsonProperty("xy") Float[] xy, @JsonProperty("effect") String effect,
        @JsonProperty("colormode") String colorMode) {
    this.on = on;
    this.brightness = brightness;
    this.hue = hue;
    this.saturation = saturation;
    this.ct = ct;
    this.xy = xy != null ? Arrays.copyOf(xy, 2) : null;
    this.effect = effect;
    this.colorMode = colorMode;
}

From source file:com.bitbreeds.webrtc.signaling.BindingService.java

public byte[] processBindingRequest(byte[] data, String userName, String password, InetSocketAddress sender) {

    logger.trace("Input: " + Hex.encodeHexString(data));

    StunMessage msg = StunMessage.fromBytes(data);

    logger.trace("InputParsed: " + msg);

    byte[] content = SignalUtil.joinBytesArrays(SignalUtil.twoBytesFromInt(0x01),
            SignalUtil.xor(SignalUtil.twoBytesFromInt(sender.getPort()),
                    Arrays.copyOf(msg.getHeader().getCookie(), 2)),
            SignalUtil.xor(sender.getAddress().getAddress(), msg.getHeader().getCookie()));

    StunAttribute attr = new StunAttribute(StunAttributeTypeEnum.XOR_MAPPED_ADDRESS, content);

    StunAttribute user = msg.getAttributeSet().get(StunAttributeTypeEnum.USERNAME);
    String strUser = new String(user.toBytes()).split(":")[0].trim();

    msg.validate(password, data);/*  w  w w. j  a  v a 2  s .  co m*/

    HashMap<StunAttributeTypeEnum, StunAttribute> outSet = new HashMap<>();
    outSet.put(StunAttributeTypeEnum.XOR_MAPPED_ADDRESS, attr);
    outSet.putAll(msg.getAttributeSet());

    StunMessage output = StunMessage.fromData(StunRequestTypeEnum.BINDING_RESPONSE, msg.getHeader().getCookie(),
            msg.getHeader().getTransactionID(), outSet, true, true, strUser, password);

    byte[] bt = output.toBytes();
    logger.trace("Response: " + Hex.encodeHexString(bt));
    return bt;
}

From source file:de.csdev.ebus.command.datatypes.ext.EBusTypeDateTime.java

@Override
public EBusDateTime decodeInt(byte[] data) throws EBusTypeException {

    IEBusType<Object> dateType = getDateType();
    IEBusType<Object> timeType = getTimeType();

    byte[] timeData = null;
    byte[] dateData = null;

    if (timeFirst) {
        timeData = Arrays.copyOf(data, timeType.getTypeLength());
        dateData = Arrays.copyOfRange(data, timeData.length, timeData.length + dateType.getTypeLength());
    } else {/*from   www  .j  av  a 2 s .c  om*/
        dateData = Arrays.copyOf(data, dateType.getTypeLength());
        timeData = Arrays.copyOfRange(data, dateData.length, dateData.length + timeType.getTypeLength());
    }

    EBusDateTime time = (EBusDateTime) timeType.decode(timeData);
    EBusDateTime date = (EBusDateTime) dateType.decode(dateData);

    Calendar calendar = date.getCalendar();

    calendar.set(Calendar.HOUR_OF_DAY, time.getCalendar().get(Calendar.HOUR_OF_DAY));
    calendar.set(Calendar.MINUTE, time.getCalendar().get(Calendar.MINUTE));
    calendar.set(Calendar.SECOND, time.getCalendar().get(Calendar.SECOND));

    return new EBusDateTime(calendar, false, false);
}

From source file:com.ktds.ldap.populator.AttributeCheckAttributesMapper.java

public void setAbsentAttributes(String[] absentAttributes) {
    this.absentAttributes = Arrays.copyOf(absentAttributes, absentAttributes.length);
}

From source file:org.dkpro.tc.ml.report.util.ScatterplotRenderer.java

public ScatterplotRenderer(double[] gold, double[] prediction) {
    if (gold.length != prediction.length) {
        throw new IllegalArgumentException("A equal number of gold and prediction values is required.");
    }// www . j  av a  2  s  .c o m

    if (gold.length == 0) {
        throw new IllegalArgumentException("Cannot draw without values.");
    }

    min = Math.min(getMin(gold), getMin(prediction));
    max = Math.max(getMax(gold), getMax(prediction));

    DefaultXYDataset dataset = new DefaultXYDataset();
    double[][] data = new double[2][gold.length];
    data[0] = gold;
    data[1] = Arrays.copyOf(prediction, prediction.length);
    dataset.addSeries("Scatterplot", data);
    aDataset = dataset;
}

From source file:gdsc.smlm.filters.BlockAverageDataProcessor.java

/**
 * @param data// w  w  w  .jav a2 s  .c o m
 * @param width
 * @param height
 * @return
 */
@Override
public float[] process(float[] data, int width, int height) {
    float[] smoothData = data;
    if (smooth > 0) {
        // Smoothing destructively modifies the data so create a copy
        smoothData = Arrays.copyOf(data, width * height);

        // Check upper limits are safe
        final int tmpSmooth = FastMath.min((int) smooth, FastMath.min(width, height) / 2);

        if (tmpSmooth <= getBorder()) {
            filter.rollingBlockAverageInternal(smoothData, width, height, tmpSmooth);
        } else {
            filter.rollingBlockAverage(smoothData, width, height, tmpSmooth);
        }
    }
    return smoothData;
}

From source file:com.simiacryptus.text.CompressionUtil.java

/**
 * Encode lz byte [ ].//from   ww  w  .  ja  v  a2 s  .  c  o  m
 *
 * @param bytes      the bytes
 * @param dictionary the dictionary
 * @return the byte [ ]
 */
public static byte[] encodeLZ(byte[] bytes, String dictionary) {
    byte[] output = new byte[(int) (bytes.length * 1.05 + 32)];
    Deflater compresser = new Deflater();
    try {
        compresser.setInput(bytes);
        if (null != dictionary && !dictionary.isEmpty()) {
            byte[] bytes2 = dictionary.getBytes("UTF-8");
            compresser.setDictionary(bytes2);
        }
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
    compresser.finish();
    int compressedDataLength = compresser.deflate(output);
    compresser.end();
    return Arrays.copyOf(output, compressedDataLength);
}

From source file:org.bigtester.ate.model.casestep.RepeatDataRefreshEvent.java

/**
 * Instantiates a new repeat data refresh event.
 *
 * @param source//from  ww w . j  a v a 2 s  .  c  o m
 *            the source
 * @param repeatStepInvokePathNodes
 *            the repeat step invoke path nodes
 * @param iteration
 *            the iteration
 */
public RepeatDataRefreshEvent(RepeatStep source, TreeNode[] repeatStepInvokePathNodes, int iteration) {
    super(source);
    TreeNode[] temp = Arrays.copyOf(repeatStepInvokePathNodes, repeatStepInvokePathNodes.length);
    if (null == temp)
        throw GlobalUtils.createInternalError("error in copying array, repeatStepInvokePathNodes");
    else
        this.repeatStepInvokePathNodes = temp;
    this.iteration = iteration;
}