Example usage for org.apache.commons.lang ArrayUtils subarray

List of usage examples for org.apache.commons.lang ArrayUtils subarray

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils subarray.

Prototype

public static boolean[] subarray(boolean[] array, int startIndexInclusive, int endIndexExclusive) 

Source Link

Document

Produces a new boolean array containing the elements between the start and end indices.

Usage

From source file:com.amalto.core.load.context.StateContextSAXWriter.java

public void writeCharacters(XMLStreamReader reader) throws Exception {
    char[] characters = reader.getTextCharacters();
    int textStart = reader.getTextStart();
    char[] chars = ArrayUtils.subarray(characters, textStart, textStart + reader.getTextLength());
    if (escapeCharacters) {
        chars = StringEscapeUtils.escapeXml(new String(chars)).toCharArray();
    }//w w w.jav  a  2 s .  c  o m
    contentHandler.characters(chars, 0, chars.length);
}

From source file:at.gv.egiz.bku.slcommands.impl.cms.ReferencedHashDataInput.java

public InputStream getHashDataInput() throws IOException {

    InputStream hashDataInputStream = urlDereferencer.dereference(urlReference).getStream();

    try {//from   w w  w .  j a  v a  2s  .  c  o m
        byte[] content = IOUtils.toByteArray(hashDataInputStream);

        if (excludedByteRange != null) {

            int from = excludedByteRange.getFrom().intValue();
            int to = excludedByteRange.getTo().intValue();

            byte[] signedContent = ArrayUtils.addAll(ArrayUtils.subarray(content, 0, from),
                    ArrayUtils.subarray(content, to, content.length));

            return new ByteArrayInputStream(signedContent);

        } else {
            return new ByteArrayInputStream(content);
        }

    } finally {
        hashDataInputStream.close();
    }
}

From source file:com.mycompany.monroelabsm.Seed.java

public Seed(byte[] seed) {
    //plug in big array into all seed values.
    serial = ArrayUtils.subarray(seed, 0, 13);
    operator = ArrayUtils.subarray(seed, 13, 16);
    heading = ArrayUtils.subarray(seed, 16, 17);
    gpsx = ArrayUtils.subarray(seed, 17, 20);
    gpsy = ArrayUtils.subarray(seed, 20, 23);
    crypto = ArrayUtils.subarray(seed, 23, 25);
    fiat = ArrayUtils.subarray(seed, 25, 27);
    denomination = ArrayUtils.subarray(seed, 27, 28);
    time = ArrayUtils.subarray(seed, 28, 32);
}

From source file:com.bskyb.cg.environments.message.MessageFormatFactory.java

protected void initFromProperties() throws Exception {

    PropertiesConfiguration propertiesConfiguration = keysToClassNames.getConfigure();
    Iterator<String> iterator = propertiesConfiguration.getKeys();
    String key;//from  ww w . j  a  v a2s. c  om
    String className;
    String[] params = null;
    while (iterator.hasNext()) {
        key = (String) iterator.next();
        params = propertiesConfiguration.getStringArray(key);
        className = params[0];
        Class<MessageFormat> cls = (Class<MessageFormat>) Class.forName(className);
        classes.put(key, cls);
        args.put(key, ArrayUtils.subarray(params, 0, params.length));
    }

}

From source file:com.jaspersoft.jasperserver.repository.test.RepositoryServiceDependentResourcesTest.java

@BeforeMethod
public void log(Method m) {
    logger.info(msg("@@@ Running -> %s", m.getName()));

    expectedOrder = ArrayUtils.toString(uriList);
    expectedOrderForTopFive = ArrayUtils.toString(ArrayUtils.subarray(uriList, 0, 5));
}

From source file:com.github.bmadecoder.Authenticator.java

private static int selectInt(byte input[]) {
    int i = selectPos(input);
    byte[] subarray = ArrayUtils.subarray(input, i, i + 4);
    subarray[0] = (byte) (subarray[0] & 0x7f);
    int readSwappedInteger = EndianUtils.readSwappedInteger(subarray, 0);
    int result = EndianUtils.swapInteger(readSwappedInteger);
    return result;
}

From source file:com.baidu.api.client.core.DownloadUtil.java

/**
 * Download the file pointed by the url and return the content as byte array.
 *
 * @param strUrl         The Url to be downloaded.
 * @param connectTimeout Connect timeout in milliseconds.
 * @param readTimeout    Read timeout in milliseconds.
 * @param maxFileSize    Max file size in BYTE.
 * @return The file content as byte array.
 *///  ww  w  .j a  v a 2 s  . c  o m
public static byte[] downloadFile(String strUrl, int connectTimeout, int readTimeout, int maxFileSize) {
    InputStream in = null;
    try {
        URL url = new URL(strUrl); // URL?
        URLConnection ucon = url.openConnection();
        ucon.setConnectTimeout(connectTimeout);
        ucon.setReadTimeout(readTimeout);
        ucon.connect();
        if (ucon.getContentLength() > maxFileSize) {
            String msg = "File " + strUrl + " size [" + ucon.getContentLength()
                    + "] too large, download stoped.";
            throw new ClientInternalException(msg);
        }
        if (ucon instanceof HttpURLConnection) {
            HttpURLConnection httpCon = (HttpURLConnection) ucon;
            if (httpCon.getResponseCode() > 399) {
                String msg = "Failed to download file " + strUrl + " server response "
                        + httpCon.getResponseMessage();
                throw new ClientInternalException(msg);
            }
        }
        in = ucon.getInputStream(); // ?
        byte[] byteBuf = new byte[BUFFER_SIZE];
        byte[] ret = null;
        int count, total = 0;
        // ??
        while ((count = in.read(byteBuf, total, BUFFER_SIZE - total)) > 0) {
            total += count;
            if (total + 124 >= BUFFER_SIZE)
                break;
        }
        if (total < BUFFER_SIZE - 124) {
            ret = ArrayUtils.subarray(byteBuf, 0, total);
        } else {
            ByteArrayOutputStream bos = new ByteArrayOutputStream(MATERIAL_SIZE);
            count = total;
            total = 0;
            do {
                bos.write(byteBuf, 0, count);
                total += count;
                if (total > maxFileSize) {
                    String msg = "File " + strUrl + " size exceed [" + maxFileSize + "] download stoped.";
                    throw new ClientInternalException(msg);
                }
            } while ((count = in.read(byteBuf)) > 0);
            ret = bos.toByteArray();
        }
        if (ret.length < MIN_SIZE) {
            String msg = "File " + strUrl + " size [" + maxFileSize + "] too small.";
            throw new ClientInternalException(msg);
        }
        return ret;
    } catch (IOException e) {
        String msg = "Failed to download file " + strUrl + " msg=" + e.getMessage();
        throw new ClientInternalException(msg);
    } finally {
        try {
            if (in != null)
                in.close();
        } catch (IOException e) {
            // ?
            System.out.println("Exception while close url - " + e.getMessage());
        }
    }
}

From source file:com.tylerhyperHD.FreedomHostingMod.Commands.Command_smite.java

@Override
public boolean onCommand(CommandSender sender, Command cmd, String string, String[] args) {

    if (F_Debug.isDebugOn()) {
        F_Log.info("Server ran command successfully");
    }//w w w. j  av a 2  s .c  o  m

    if (!(sender instanceof Player)) {
        senderMsg("You must be in-game to use this command.", sender);
        return true;
    }

    if (args.length == 0) {
        senderMsg("Usage: /smite <player> <reason>", sender);
        return true;
    } else if (args.length == 1) {
        Player player = Bukkit.getPlayer(args[0]);
        Bukkit.broadcastMessage(ChatColor.RED + player.getName() + " has been naughty.");
        Bukkit.broadcastMessage(ChatColor.RED + "They have thus been smitten!");

        final Location targetPos = player.getLocation();
        final World world = player.getWorld();
        for (int x = -1; x <= 1; x++) {
            for (int z = -1; z <= 1; z++) {
                final Location strike_pos = new Location(world, targetPos.getBlockX() + x,
                        targetPos.getBlockY(), targetPos.getBlockZ() + z);
                world.strikeLightning(strike_pos);
            }
        }

        player.setGameMode(GameMode.SURVIVAL);
        player.getInventory().clear();
        player.setHealth(0.0);
    } else if (args.length > 1) {
        final String reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
        Player player = Bukkit.getPlayer(args[0]);

        Bukkit.broadcastMessage(ChatColor.RED + player.getName() + " has been naughty.");
        Bukkit.broadcastMessage(ChatColor.RED + "They have thus been smitten!");
        Bukkit.broadcastMessage(ChatColor.GOLD + "Reason: " + reason);

        final Location targetPos = player.getLocation();
        final World world = player.getWorld();
        for (int x = -1; x <= 1; x++) {
            for (int z = -1; z <= 1; z++) {
                final Location strike_pos = new Location(world, targetPos.getBlockX() + x,
                        targetPos.getBlockY(), targetPos.getBlockZ() + z);
                world.strikeLightning(strike_pos);
            }
        }

        player.setGameMode(GameMode.SURVIVAL);
        player.getInventory().clear();
        player.setHealth(0.0);
    }
    return true;
}

From source file:com.preferanser.shared.domain.EditorTest.java

@BeforeMethod
public void setUp() throws Exception {
    Clock.setNow(new Date(1));
    name = "name";
    description = "description";
    southCards = (Card[]) ArrayUtils.subarray(Card.values(), 0, 10);
    eastCards = (Card[]) ArrayUtils.subarray(Card.values(), 10, 20);
    westCards = (Card[]) ArrayUtils.subarray(Card.values(), 20, 30);
    editor = new Editor().setName(name).setDescription(description).setThreePlayers()
            .setWidow(Widow.fromArray((Card[]) ArrayUtils.subarray(Card.values(), 30, 32)))
            .setHandContract(SOUTH, Contract.SIX_SPADE).setHandContract(EAST, Contract.WHIST)
            .setHandContract(WEST, Contract.PASS).putCards(SOUTH, southCards).putCards(EAST, eastCards)
            .putCards(WEST, westCards).setFirstTurn(SOUTH);

    widow = new Widow(Card.CLUB_KING, CLUB_QUEEN);
}

From source file:app.Des.java

private String cipher(int[] message, List<int[]> keys) {
    int[] messPermuted = this.tables.getIP_Message(message);
    int[] messL = ArrayUtils.subarray(messPermuted, 0, messPermuted.length / 2);
    int[] messR = ArrayUtils.subarray(messPermuted, messPermuted.length / 2, messPermuted.length);

    for (int[] key1 : keys) {
        int[] eMessR = this.tables.getE_Message(messR);

        int[] xorResult = new int[eMessR.length];
        for (int i = 0; i < eMessR.length; i++) {
            xorResult[i] = binMath.xor(eMessR[i], key1[i]);
        }//from   w w  w.  j a  v a2 s .c  o m

        String row = "";
        String column = "";
        int[] sTransformedMess = new int[32];
        int sTransformedIndex = 0;
        int sTableIndex = 0;
        for (int i = 0; i < xorResult.length; i = i + 6, sTableIndex++) {
            row = String.valueOf(xorResult[i]) + String.valueOf(xorResult[i + 5]);
            column = String.valueOf(xorResult[i + 1]) + String.valueOf(xorResult[i + 2])
                    + String.valueOf(xorResult[i + 3]) + String.valueOf(xorResult[i + 4]);

            int sTableNumber = this.tables.getSTables().get(sTableIndex)[Integer.parseInt(row, 2)][Integer
                    .parseInt(column, 2)];
            String binary = this.binMath.intToString(sTableNumber);

            for (int bin = 0; bin < binary.length(); bin++) {
                sTransformedMess[sTransformedIndex + bin] = Integer.parseInt(binary.charAt(bin) + "");
            }
            sTransformedIndex += binary.length();
        }
        int[] pMessage = this.tables.getP_Message(sTransformedMess);

        int[] tempR = new int[messR.length];
        for (int i = 0; i < messL.length; i++) {
            tempR[i] = binMath.xor(messL[i], pMessage[i]);
        }
        messL = ArrayUtils.clone(messR);
        messR = ArrayUtils.clone(tempR);
    }
    int[] lastPermuted = this.tables.getIPInverse_Message(ArrayUtils.addAll(messR, messL));
    String hex = binMath.fromBinStringToHexString(getString(lastPermuted, 0));
    return hex;
}