List of usage examples for org.apache.commons.lang ArrayUtils subarray
public static boolean[] subarray(boolean[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new boolean
array containing the elements between the start and end indices.
From source file:com.ms.commons.standalone.job.JobRunner.java
private static String[] getNewArgs(String[] args) { String[] NewArgs = (String[]) ArrayUtils.subarray(args, 2, args.length + 1); return NewArgs; }
From source file:de.tudarmstadt.ukp.dkpro.core.api.datasets.Dataset.java
default Split getSplit(double aTrainRatio, double aTestRatio) { Log LOG = LogFactory.getLog(getClass()); File[] all = getDataFiles();//from w w w .ja va 2 s.c o m Arrays.sort(all, (File a, File b) -> { return a.getName().compareTo(b.getName()); }); LOG.info("Found " + all.length + " files"); int trainPivot = (int) Math.round(all.length * aTrainRatio); int testPivot = (int) Math.round(all.length * aTestRatio) + trainPivot; File[] train = (File[]) ArrayUtils.subarray(all, 0, trainPivot); File[] test = (File[]) ArrayUtils.subarray(all, trainPivot, testPivot); LOG.debug("Assigned " + train.length + " files to training set"); LOG.debug("Assigned " + test.length + " files to test set"); if (testPivot != all.length) { LOG.info("Files missing from split: [" + (all.length - testPivot) + "]"); } return new SplitImpl(train, test, null); }
From source file:com.github.neoio.net.message.staging.file.TestFileMessageStaging.java
@Test public void test_tempRead() { ByteBuffer buffer = ByteBuffer.allocate(1024); buffer.put("Hello World".getBytes()); buffer.flip();//from w w w . j a v 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:com.stehno.cola.Pop3ServerHandler.java
@Override public void messageReceived(final IoSession session, final Object message) throws Exception { final String[] line = StringUtils.split(message.toString(), ' '); final Pop3Command command = commandFactory.findCommand(line[0]); if (command != null) { command.execute(session, (String[]) ArrayUtils.subarray(line, 1, line.length)); } else {// w ww. j av a 2 s . co m session.write("-ERR\r"); log.info("Nowhere: {}", line); } }
From source file:name.richardson.james.bukkit.utilities.command.argument.JoinedPositionalArgument.java
@Override protected String[] getMatch(final String arguments) { String[] values = null;// w w w .j a v a 2s. co m String[] isolatedArguments = removeOptionsAndSwitches(arguments); if (isolatedArguments != null && isolatedArguments.length > 0) { if (isolatedArguments.length - 1 >= getPosition()) { values = (String[]) ArrayUtils.subarray(isolatedArguments, getPosition(), isolatedArguments.length); } } return values; }
From source file:de.softwareforge.pgpsigner.commands.SignEventCommand.java
@Override public void executeInteractiveCommand(final String[] args) { getContext().setSignEvent(StringUtils.join(ArrayUtils.subarray(args, 1, args.length), ' ')); }
From source file:cz.zeno.miner.FpgaWork.java
@Override public byte[] getWork() { //original header is extended with custom target and jobid (for miner internals) //initial nonce, target, jobID try {/*from w w w. j ava 2 s . co m*/ byte[] adder; //scrypt fpga needs different four bytes from target if (isScrypt) adder = ArrayUtils.addAll(ArrayUtils.addAll(Utils.hexStringToByteArray("00000000"), ArrayUtils.subarray(target, 2, 6)), jobID); else adder = ArrayUtils.addAll(ArrayUtils.addAll(Utils.hexStringToByteArray("00000000"), ArrayUtils.subarray(target, 4, 8)), jobID); byte[] work = ArrayUtils.addAll(ArrayUtils.addAll( ArrayUtils.addAll(Utils.swapEndian(ArrayUtils.addAll(version, prevhash)), merkleRoot), Utils.swapEndian(ArrayUtils.addAll(ntime, nbits))), adder); return work; } catch (DecoderException ex) { Logger.getLogger(FpgaWork.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:de.forsthaus.backend.service.impl.IpToCountryServiceImpl.java
/** * Converts an ip-address to a long value.<br> * //from w w w .j a va 2 s . c o m * @param address * @return */ private static long inetAddressToLong(InetAddress address) { if (address.isAnyLocalAddress()) return 0l; final byte[] bs; if (address instanceof Inet4Address) { bs = address.getAddress(); } else if (address instanceof Inet6Address) { if (((Inet6Address) address).isIPv4CompatibleAddress()) { // take the last 4 digits bs = ArrayUtils.subarray(address.getAddress(), 12, 16); } else { throw new RuntimeException("IPv6 not supported!"); } } else { throw new RuntimeException(); } return bs[0] * 16777216l + bs[1] * 65536 + bs[2] * 256 + bs[3]; }
From source file:com.github.neoio.net.message.staging.memory.TestMemoryMessageStaging.java
@Test public void test_tempWrite() { ByteBuffer buffer = ByteBuffer.allocate(1024); buffer.put("Hello World".getBytes()); buffer.rewind();//from www .ja va 2 s . c o m staging.writeTempWriteBytes(buffer); Assert.assertTrue(staging.hasTempWriteBytes()); buffer.clear(); staging.readTempWriteBytes(buffer); Assert.assertEquals("Hello World", new String(ArrayUtils.subarray(buffer.array(), 0, "Hello World".getBytes().length))); staging.resetTempWriteBytes(); Assert.assertFalse(staging.hasTempWriteBytes()); }
From source file:app.Des.java
public void doDesFile(int[][] content, String location, String name) throws IOException { List<int[]> keys = doKey(); RWBinaryFile file = new RWBinaryFile(); int[][] ciphered = new int[content.length / 8][]; int[][] deciphered = new int[content.length][]; int contentRow = 0; int outputRow = 0; while (contentRow < content.length) { int[] contentCopy = new int[0]; for (int i = 0; i < 8; i++, contentRow++) { contentCopy = ArrayUtils.addAll(contentCopy, ArrayUtils.clone(content[contentRow])); }//from ww w .j a v a2s . c om String out = cipher(contentCopy, keys); int[] temp = this.binMath.fromHexStringToBin(out, B_64); ciphered[outputRow] = ArrayUtils.clone(temp); outputRow++; } int[][] cipheredToWrite = new int[content.length][]; int index = 0; for (int[] tab : ciphered) { for (int i = 0; i < tab.length; i = i + 8) { cipheredToWrite[index] = ArrayUtils.subarray(tab, i, i + 8); index++; } } file.write(cipheredToWrite, location + "ciphered_" + name); keys = reverseList(keys); int output2Row = 0; int cipheredRow = 0; while (output2Row < ciphered.length) { String out = ""; out = cipher(ciphered[cipheredRow], keys); int[] temp = binMath.fromHexStringToBin(out, B_64); for (int indexTemp = 0; indexTemp < 64; indexTemp = indexTemp + 8) { deciphered[output2Row] = ArrayUtils.subarray(temp, indexTemp, indexTemp + 8); output2Row++; } cipheredRow++; } file.write(deciphered, location + "deciphered_" + name); }