Example usage for java.util Arrays copyOfRange

List of usage examples for java.util Arrays copyOfRange

Introduction

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

Prototype

public static boolean[] copyOfRange(boolean[] original, int from, int to) 

Source Link

Document

Copies the specified range of the specified array into a new array.

Usage

From source file:com.metawiring.load.generator.GeneratorInstantiator.java

private static Object[] parseGeneratorArgs(String generatorType) {
    String[] parts = generatorType.split(":");
    return Arrays.copyOfRange(parts, 1, parts.length);
}

From source file:com.stratio.explorer.converters.PropertiesToStringConverter.java

private String deleteHeaderLine(String string) {
    String[] strings = string.split("\\n");
    List<String> withOutHeader = Arrays.asList(Arrays.copyOfRange(strings, 1, strings.length));
    Collections.reverse(withOutHeader);
    return StringUtils.join(withOutHeader, lineSeparator);

}

From source file:com.bitbreeds.webrtc.sctp.model.SCTPHeader.java

public static SCTPHeader fromBytes(byte[] bytes) {
    if (bytes.length != 12) {
        throw new IllegalArgumentException("Bytes given are incorrect length to be an SCTP header: "
                + " length: " + bytes.length + "  data:" + Hex.encodeHexString(bytes));
    }/*from   www. j a  va 2s  .  c  om*/
    return new SCTPHeader(SignalUtil.intFromTwoBytes(Arrays.copyOf(bytes, 2)),
            SignalUtil.intFromTwoBytes(Arrays.copyOfRange(bytes, 2, 4)),
            SignalUtil.bytesToLong(Arrays.copyOfRange(bytes, 4, 8)),
            SignalUtil.bytesToLong(Arrays.copyOfRange(bytes, 8, 12)));
}

From source file:me.bramhaag.discordselfbot.commands.fun.CommandLMGTFY.java

@Command(name = "lmgtfy", minArgs = 1)
public void execute(@NonNull Message message, @NonNull TextChannel channel, @NonNull String[] args) {
    String tinyURL = "http://tinyurl.com/api-create.php?url=";
    String lmgtfyURL = "http://lmgtfy.com?q=";

    String url;/*from ww  w . j  a v  a2s .c om*/

    try {
        if (args[0].equalsIgnoreCase("--expanded") || args[0].equalsIgnoreCase("-e") && args.length >= 2) {
            url = lmgtfyURL + URLEncoder.encode(StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " "),
                    "UTF-8");
        } else {
            Document doc;
            try {
                doc = Jsoup
                        .connect(tinyURL + lmgtfyURL + URLEncoder.encode(StringUtils.join(args, " "), "UTF-8"))
                        .get();
            } catch (IOException e) {
                e.printStackTrace();

                Util.sendError(message, e.getMessage());
                return;
            }

            url = doc.body().text();
        }
    } catch (UnsupportedEncodingException e) {
        Util.sendError(message, e.getMessage());
        return;
    }

    message.editMessage("<" + url + ">").queue();
}

From source file:bigdataproject.KDistances.java

void getKSortedNearestNeighbors(int k) {
    double[] allK = new double[k * samples.length];
    int index = 0;
    for (double[] distRow : distanceMatrix) {
        Arrays.sort(distRow);/* w  ww.  j  ava 2 s .c om*/
        double[] subK = Arrays.copyOfRange(distRow, 1, k);
        for (int j = 0; j < subK.length; j++) {
            final double value = subK[j];
            if (!DoubleStream.of(allK).anyMatch(x -> x == value)) {
                allK[index++] = value;
            }
        }
    }
    double[] finalArray = Arrays.copyOfRange(allK, 0, index);
    Arrays.sort(finalArray);
    Karray = finalArray;
}

From source file:com.zotoh.core.crypto.BaseOfuscator.java

/**
 * Set the encryption key for future obfuscation operations.  Typically this is
 * called once only at the start of the main application.
 * //  w ww .  j av a 2s . com
 * @param key
 */
public static void setKey(byte[] key) {
    tstNEArray("enc-key", key);
    int len = key.length;
    if (T3_DES.equals(ALGO)) {
        if (key.length < 24) {
            throw new IllegalArgumentException("Encryption key length must be 24, using TripleDES");
        }
        if (key.length > 24) {
            len = 24;
        }
    }
    _key = Arrays.copyOfRange(key, 0, len);
}

From source file:me.bramhaag.discordselfbot.commands.admin.CommandEvaluate.java

@Command(name = "evaluate", aliases = { "eval", "e" }, minArgs = 1)
public void execute(@NonNull Message message, @NonNull TextChannel channel, @NonNull String[] args) {

    String input = Util.combineArgs(Arrays.copyOfRange(args, 1, args.length));
    Evaluate.Language language = Evaluate.Language.getLanguage(args[0]);

    if (language == null) {
        language = Evaluate.Language.JAVASCRIPT;
        input = Util.combineArgs(args);
    }//from   w w w .j a va 2s.  c  o  m

    input = input.startsWith("```") && input.endsWith("```") ? input.substring(3, input.length() - 3) : input;

    Evaluate.Result result = language.evaluate(Collections.unmodifiableMap(Stream
            .of(ent("jda", message.getJDA()), ent("channel", message.getChannel()),
                    ent("guild", message.getGuild()), ent("msg", message), ent("user", message.getAuthor()),
                    ent("member", message.getGuild().getMember(message.getAuthor())),
                    ent("bot", message.getJDA().getSelfUser()))
            .collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue))),
            input);

    message.editMessage(new EmbedBuilder()
            .setTitle("Evaluate " + StringUtils.capitalize(language.name().toLowerCase()), null)
            .addField("Input",
                    new MessageBuilder().appendCodeBlock(input, language.name().toLowerCase()).build()
                            .getRawContent(),
                    true)
            .addField("Output",
                    new MessageBuilder().appendCodeBlock(result.getOutput(), "javascript").build()
                            .getRawContent(),
                    true)
            .setFooter(result.getStopwatch().elapsed(TimeUnit.NANOSECONDS) == 0
                    ? Constants.CROSS_EMOTE + " An error occurred"
                    : String.format(Constants.CHECK_EMOTE + " Took %d ms (%d ns) to complete | %s",
                            result.getStopwatch().elapsed(TimeUnit.MILLISECONDS),
                            result.getStopwatch().elapsed(TimeUnit.NANOSECONDS), Util.generateTimestamp()),
                    null)
            .setColor(color).build()).queue();
}

From source file:mx.bigdata.anyobject.MapBasedAnyObject.java

private <T> T get(Map inner, String[] key) {
    Object o = inner.get(key[0]);
    return (T) ((key.length > 1) ? get((Map) o, Arrays.copyOfRange(key, 1, key.length)) : o);
}

From source file:edu.kit.trufflehog.model.network.MacAddress.java

public MacAddress(long address) throws InvalidMACAddress {

    this.address = address;

    if (this.address > 0xFFFFFFFFFFFFL || this.address < 0) {
        throw new InvalidMACAddress(address);
    }//  w  ww  . ja v  a  2s . co  m

    hashcode = (new Long(address)).hashCode();
    // transform to byte array
    final byte[] extractedBytes = ByteBuffer.allocate(8).putLong(address).array();
    bytes = Arrays.copyOfRange(extractedBytes, 2, 8);

    // set multicast bit
    isMulticast = (bytes[0] & 1) == 1;

    // set string representation
    final List<Byte> bytes = Arrays.asList(ArrayUtils.toObject(toByteArray()));
    addressString = bytes.stream().map(b -> String.format("%02x", b)).collect(Collectors.joining(":"));
}

From source file:com.tc.simple.apn.factories.FeedbackFactory.java

public List<Feedback> createFeedback(InputStream in) {
    List<Feedback> list = new ArrayList<Feedback>();
    try {/*  w ww.j a va2s . c om*/

        byte[] byteMe = IOUtils.toByteArray(in);

        int startRange = 0;

        int endRange = 38; //38 byte chunks per feedback item.

        while (startRange < byteMe.length) {

            //init the value object to hold the feedback data.
            Feedback feedback = new Feedback();

            //build the item based on range
            byte[] item = Arrays.copyOfRange(byteMe, startRange, endRange);//38 byte chunks.

            byte[] date = Arrays.copyOfRange(item, 0, 4);

            byte[] size = Arrays.copyOfRange(item, 4, 6);

            byte[] token = Arrays.copyOfRange(item, 6, item.length);

            ByteBuffer dateWrap = ByteBuffer.wrap(date);

            ByteBuffer javaSize = ByteBuffer.wrap(size);

            //set the date (returns number of seconds from unix epoch date)
            feedback.setDate(new Date(dateWrap.getInt() * 1000L));

            //get the size of the token (should always be 32)
            feedback.setSize(javaSize.getShort());

            //drop in our encoded token (will be used as our key for marking the user's token doc as failed)
            feedback.setToken(String.valueOf(Hex.encodeHex(token)));

            //add it to our collection
            list.add(feedback);

            //increment the start range
            startRange = startRange + 38;

            //increment the end range.
            endRange = endRange + 38;

        }

    } catch (Exception e) {
        logger.log(Level.SEVERE, null, e);

    }

    return list;

}