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.yahoo.flowetl.commons.runner.Main.java

/**
 * The main method entry point.//from  ww  w  .  j  av  a  2  s . co m
 */
public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.out.println(
                Main.class.getSimpleName() + " [runner fully qualified java class name] arguments ...");
        return;
    }
    System.out.println("+Argument info:");
    StringBuilder argsStr = new StringBuilder();
    for (int i = 0; i < args.length; i++) {
        argsStr.append("(" + (i + 1) + ") " + args[i] + " [" + args[i].length() + " chars]");
        if (i + 1 != args.length) {
            argsStr.append(" ");
        }
    }
    System.out.println(argsStr);
    Map<String, Object> sysInfo = getRuntimeInfo();
    System.out.println("+Runtime info:");
    for (Entry<String, Object> e : sysInfo.entrySet()) {
        System.out.println("--- " + e.getKey() + " => " + (e.getValue() == null ? "" : e.getValue()));
    }
    String classToRun = args[0];
    Class<?> testToRun = KlassUtils.getClassForName(classToRun);
    if (KlassUtils.isAbstract(testToRun) || KlassUtils.isInterface(testToRun)) {
        System.out.println("+Runner class name that is not abstract or an interface is required!");
        return;
    }
    if (ClassUtils.isAssignable(testToRun, (Runner.class)) == false) {
        System.out.println("+Runner class name that is a instance/subclass of " + Runner.class.getSimpleName()
                + " is required!");
        return;
    }
    Class<Runner> rToRun = KlassUtils.getClassForName(classToRun);
    System.out.println("+Running program specified by runner class " + rToRun);
    Runner r = KlassUtils.getInstanceOf(rToRun, new Object[] {});
    String[] nargs = (String[]) ArrayUtils.subarray(args, 1, args.length);
    System.out.println("+Proxying to object " + r + " with arguments [" + StringUtils.join(nargs, ",") + "]");
    r.runProgram(nargs);
}

From source file:com.google.step2.util.EncodingUtil.java

public static byte[] getUtf8Bytes(String s) {
    if (s == null) {
        return ArrayUtils.EMPTY_BYTE_ARRAY;
    }//  www.  j  a va 2s.c o m
    ByteBuffer bb = UTF8.encode(s);
    return ArrayUtils.subarray(bb.array(), 0, bb.limit());
}

From source file:com.ewcms.common.io.HtmlFileUtil.java

public static String readText(InputStream is, String encoding) {
    try {/*from  ww  w .ja v  a 2  s . com*/
        byte bs[] = readByte(is);
        if (encoding.equalsIgnoreCase("UTF-8")
                && HtmlStringUtil.hexEncode(ArrayUtils.subarray(bs, 0, 3)).equals("efbbbf"))
            bs = ArrayUtils.subarray(bs, 3, bs.length);
        return new String(bs, encoding);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.baidu.terminator.plugin.signer.customized.app.CipherUtil.java

public static byte[] process(Cipher cipher, int blockSize, byte[] input)
        throws IllegalBlockSizeException, BadPaddingException, ShortBufferException {
    if (input.length <= blockSize) {
        return cipher.doFinal(input);
    }//from w  w w.  jav a2s .  c o m
    byte[] output = new byte[OUTPUT_SIZE];
    int outputSize = 0;
    for (int i = 0;; i += blockSize) {
        if (i + blockSize < input.length)
            outputSize += cipher.doFinal(input, i, blockSize, output, outputSize);
        else {
            outputSize += cipher.doFinal(input, i, input.length - i, output, outputSize);
            break;
        }
    }
    return ArrayUtils.subarray(output, 0, outputSize);
}

From source file:net.savcode.fopmr.commands.C_gtfo.java

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

    if (!Rank.isAdmin(sender)) {
        sender.sendMessage(NO_PERM);// www.j a  va2 s .c om
        return true;
    }

    if (args.length == 0) {
        return false;
    }

    final String reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
    Player target = Bukkit.getServer().getPlayer(args[0]);

    if (args.length == 1) {
        if (target == null) {
            sender.sendMessage(PLAYER_NOT_FOUND);
            return false;
        }
        FOPMR_Utils.bcastMsg(target.getName() + "has been a VERY naughty, naughty boy. \nBanning: "
                + target.getName() + ", IP: "
                + FOPMR_ConfigEntry.PlayerConfig().getString(target.getUniqueId().toString() + ".ip"));
        target.kickPlayer(ChatColor.RED + "GTFO");
        FOPMR_Bans.addBan(target, sender);
    }

    if (args.length > 1) {
        if (reason != null) {
            FOPMR_Utils.bcastMsg(target.getName() + "has been a VERY naughty, naughty boy. \nBanning: "
                    + target.getName() + ", IP: "
                    + FOPMR_ConfigEntry.PlayerConfig().getString(target.getUniqueId().toString() + ".ip")
                    + "\nReason: " + ChatColor.GOLD + reason);
            target.kickPlayer(ChatColor.RED + "GTFO");
            FOPMR_Bans.addBan(target, sender, reason);
        }
    }
    return true;
}

From source file:cz.zeno.miner.Utils.java

public static byte[] swapEndian(byte[] data) {
    //reverse each four bytes
    for (int i = 0; i < data.length / 4; i++) {
        byte[] msub = ArrayUtils.subarray(data, i * 4, i * 4 + 4);
        ArrayUtils.reverse(msub);//from w w w  . ja v a 2s .  c  o  m
        System.arraycopy(msub, 0, data, i * 4, 4);
    }
    return data;
}

From source file:net.michaelpigg.xbeelib.protocol.impl.NodeDiscoveryResponseFormatter.java

public void formatTo(Formatter formatter, int flags, int width, int precision) {
    final StringBuilder sb = new StringBuilder("ND response: ");
    sb.append(format("Frame ID = %d;", response.getFrameId()))
            .append(format("Status = %s;", response.getStatus().toString()));

    final byte[] responseBytes = response.getResponse();
    if (response.getStatus() == AtCommandStatus.OK && responseBytes.length == 0) {
        sb.append("No more nodes found.");
    } else {/*from   w  w w.  jav a2  s  .c o  m*/
        sb.append(format("Address = %s;", Hex.encodeHexString(ArrayUtils.subarray(responseBytes, 2, 10))));
        sb.append(format("Signal strength = %d;", responseBytes[11]));
        final byte[] niBytes = ArrayUtils.subarray(responseBytes, 12, responseBytes.length);
        if (niBytes.length > 1) {
            sb.append(format("Node identifier = %s", niBytes));
        }
    }

    formatter.format(sb.toString());

}

From source file:com.github.neoio.net.message.staging.memory.TestMemoryMessageStaging.java

@Test
public void test_tempRead() {
    ByteBuffer buffer = ByteBuffer.allocate(1024);

    buffer.put("Hello World".getBytes());
    buffer.rewind();/*from  w w  w . j av a 2  s  .c  o  m*/
    staging.writeTempReadBytes(buffer);
    Assert.assertTrue(staging.hasTempReadBytes());

    buffer.clear();
    staging.readTempReadBytes(buffer);
    Assert.assertEquals("Hello World",
            new String(ArrayUtils.subarray(buffer.array(), 0, "Hello World".getBytes().length)));
    staging.resetTempReadBytes();

    Assert.assertFalse(staging.hasTempReadBytes());
}

From source file:alluxio.master.journal.ProtoBufJournalFormatterTest.java

@Test
public void truncatedEntryDoesntFail() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ProtoBufJournalFormatter formatter = new ProtoBufJournalFormatter();
    formatter.serialize(//from w  w w. ja  v  a  2  s . co  m
            JournalEntry.newBuilder().setCompleteFile(CompleteFileEntry.newBuilder().setId(10)).build(), baos);
    byte[] serializedEntry = baos.toByteArray();
    for (int i = 1; i < serializedEntry.length; i++) {
        byte[] truncated = ArrayUtils.subarray(serializedEntry, 0, serializedEntry.length - i);
        Assert.assertEquals(null, formatter.deserialize(new ByteArrayInputStream(truncated)).read());
    }
}

From source file:com.haulmont.cuba.gui.xml.layout.loaders.AssignActionPostInitTask.java

@Override
public void execute(ComponentLoader.Context context, Frame window) {
    String[] elements = ValuePathHelper.parse(actionName);
    if (elements.length > 1) {
        final String id = elements[elements.length - 1];
        String[] subPath = (String[]) ArrayUtils.subarray(elements, 0, elements.length - 1);

        // using this.frame to look up the component inside the actual frame
        Component holder = this.frame.getComponent(ValuePathHelper.format(subPath));
        if (holder == null) {
            throw new GuiDevelopmentException(
                    "Can't find component: " + Arrays.toString(subPath) + " for action: " + actionName,
                    context.getFullFrameId(), "Component ID", Arrays.toString(subPath));
        }//from   w  w  w.ja v  a 2 s .  co  m

        if (!(holder instanceof Component.ActionsHolder)) {
            throw new GuiDevelopmentException(
                    String.format("Component '%s' can't contain actions", holder.getId()),
                    context.getFullFrameId(), "Holder ID", holder.getId());
        }

        Action action = ((Component.ActionsHolder) holder).getAction(id);
        if (action == null) {
            throw new GuiDevelopmentException(
                    String.format("Can't find action '%s' in '%s'", id, holder.getId()),
                    context.getFullFrameId(), "Holder ID", holder.getId());
        }

        this.component.setAction(action);
    } else if (elements.length == 1) {
        final String id = elements[0];
        Action action = getActionRecursively(frame, id);

        if (action == null) {
            String message = "Can't find action " + id;
            if (Window.Editor.WINDOW_COMMIT.equals(id) || Window.Editor.WINDOW_COMMIT_AND_CLOSE.equals(id))
                message += ". This may happen if you are opening an AbstractEditor-based screen by openWindow() method, "
                        + "for example from the main menu. Use openEditor() method or give the screen a name ended "
                        + "with '.edit' to open it as editor from the main menu.";
            throw new GuiDevelopmentException(message, context.getFullFrameId());
        }

        this.component.setAction(action);
    } else {
        throw new GuiDevelopmentException("Empty action name", context.getFullFrameId());
    }
}