Java Code Examples for org.apache.commons.lang3.ArrayUtils#subarray()
The following examples show how to use
org.apache.commons.lang3.ArrayUtils#subarray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Node.java From dht-spider with MIT License | 6 votes |
/** * byte[26] 转 Node */ public Node(byte[] bytes) { if (bytes.length != 26) throw new BTException("转换为Node需要bytes长度为26,当前为:" + bytes.length); //nodeIds nodeIdBytes = ArrayUtils.subarray(bytes, 0, 20); //ip ip = DHTUtil.bytes2Ip(ArrayUtils.subarray(bytes, 20, 24)); //ports port = DHTUtil.bytes2Port( ArrayUtils.subarray(bytes, 24, 26)); nodeId= Hex.encodeHexString(nodeIdBytes); }
Example 2
Source File: FilterBar.java From pcgen with GNU Lesser General Public License v2.1 | 6 votes |
private void layoutComponents(Container target, int xOffset, int yOffset, int maxwidth, int rowheight, SizeRequirements[] xChildren, SizeRequirements[] yChildren, int start, int end, boolean ltr) { SizeRequirements[] children = ArrayUtils.subarray(xChildren, start, end); int[] xOffsets = new int[children.length]; int[] xSpans = new int[children.length]; SizeRequirements.calculateTiledPositions(maxwidth, null, children, xOffsets, xSpans, ltr); children = ArrayUtils.subarray(yChildren, start, end); int[] yOffsets = new int[children.length]; int[] ySpans = new int[children.length]; SizeRequirements total = new SizeRequirements(rowheight, rowheight, rowheight, 0.5f); SizeRequirements.calculateAlignedPositions(rowheight, total, children, yOffsets, ySpans, ltr); for (int i = 0; i < children.length; i++) { Component c = target.getComponent(i + start); c.setBounds((int) Math.min((long) xOffset + (long) xOffsets[i], Integer.MAX_VALUE), (int) Math.min((long) yOffset + (long) yOffsets[i], Integer.MAX_VALUE), xSpans[i], ySpans[i]); } }
Example 3
Source File: GATKVariantContextUtils.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * TODO: Test. And make sure to test with reference alleles to make sure "*" is not included. * @param pileupElement pileup element representing the read. Never {@code null} * @param allele query allele. Never {@code null} * @return Whether the read contains the allele. Note that unknown can occur as well. */ public static Trilean doesReadContainAllele(final PileupElement pileupElement, final Allele allele) { Utils.nonNull(pileupElement); Utils.nonNull(allele); final byte[] readBases = ArrayUtils.subarray(pileupElement.getRead().getBases(), pileupElement.getOffset(), pileupElement.getOffset() + allele.getBases().length); if (readBases.length < allele.getBases().length) { return Trilean.UNKNOWN; } if (allele.basesMatch(readBases)) { return Trilean.TRUE; } else { return Trilean.FALSE; } }
Example 4
Source File: MrsPyramidMetadata.java From mrgeo with Apache License 2.0 | 6 votes |
public void setMaxZoomLevel(int zoomlevel) { if (imageData == null) { for (int i = 0; i <= zoomlevel; i++) { imageData = ArrayUtils.add(imageData, new ImageMetadata()); } } else if (zoomlevel < maxZoomLevel) { imageData = ArrayUtils.subarray(imageData, 0, zoomlevel + 1); } else if (zoomlevel > maxZoomLevel) { for (int i = maxZoomLevel + 1; i <= zoomlevel; i++) { imageData = ArrayUtils.add(imageData, new ImageMetadata()); } } maxZoomLevel = zoomlevel; }
Example 5
Source File: ActiveDocument.java From eclipse-encoding-plugin with Eclipse Public License 1.0 | 6 votes |
public void removeBOM() { InputStream inputStream = getInputStream(); try { byte[] bytes = IOUtils.toByteArray(getInputStream()); byte[] head3 = ArrayUtils.subarray(bytes, 0, BOM_UTF_8.length); if (Arrays.equals(head3, BOM_UTF_8)) { setContents(ArrayUtils.subarray(bytes, BOM_UTF_8.length, Integer.MAX_VALUE)); setEncoding("UTF-8"); // null if default } else { byte[] head2 = ArrayUtils.subarray(bytes, 0, BOM_UTF_16BE.length); if (Arrays.equals(head2, BOM_UTF_16BE)) { setContents(ArrayUtils.subarray(bytes, BOM_UTF_16BE.length, Integer.MAX_VALUE)); setEncoding("UTF-16BE"); } else if (Arrays.equals(head2, BOM_UTF_16LE)) { setContents(ArrayUtils.subarray(bytes, BOM_UTF_16BE.length, Integer.MAX_VALUE)); setEncoding("UTF-16LE"); } // Not support UTF-32 as in the Eclipse } } catch (IOException e) { throw new IllegalStateException(e); } finally { IOUtils.closeQuietly(inputStream); } }
Example 6
Source File: DefaultPageCreator.java From HtmlUnit-Android with Apache License 2.0 | 5 votes |
private static byte[] read(final InputStream stream, final int maxNb) throws IOException { final byte[] buffer = new byte[maxNb]; final int nbRead = stream.read(buffer); if (nbRead == buffer.length) { return buffer; } return ArrayUtils.subarray(buffer, 0, nbRead); }
Example 7
Source File: DuplexAsync.java From PacketProxy with Apache License 2.0 | 5 votes |
public byte[] prepareFastSend(byte[] data) throws Exception { int accepted_length = callOnClientPacketReceived(data); if (accepted_length <= 0){ return null; } byte[] accepted = ArrayUtils.subarray(data, 0, accepted_length); byte[] decoded = callOnClientChunkReceived(accepted); byte[] encoded = callOnClientChunkSend(decoded); return encoded; }
Example 8
Source File: SplitsProvider.java From geowave with Apache License 2.0 | 5 votes |
public static GeoWaveRowRange toRowRange( final ByteArrayRange range, final int partitionKeyLength) { final byte[] startRow = range.getStart() == null ? null : range.getStart(); final byte[] stopRow = range.getEnd() == null ? null : range.getEnd(); if (partitionKeyLength <= 0) { return new GeoWaveRowRange(null, startRow, stopRow, true, false); } else { byte[] partitionKey; boolean partitionKeyDiffers = false; if ((startRow == null) && (stopRow == null)) { return new GeoWaveRowRange(null, null, null, true, true); } else if (startRow != null) { partitionKey = ArrayUtils.subarray(startRow, 0, partitionKeyLength); if (stopRow != null) { partitionKeyDiffers = !Arrays.equals(partitionKey, ArrayUtils.subarray(stopRow, 0, partitionKeyLength)); } } else { partitionKey = ArrayUtils.subarray(stopRow, 0, partitionKeyLength); } return new GeoWaveRowRange( partitionKey, startRow == null ? null : (partitionKeyLength == startRow.length ? null : ArrayUtils.subarray(startRow, partitionKeyLength, startRow.length)), partitionKeyDiffers ? null : (stopRow == null ? null : (partitionKeyLength == stopRow.length ? null : ArrayUtils.subarray(stopRow, partitionKeyLength, stopRow.length))), true, partitionKeyDiffers); } }
Example 9
Source File: Maven2RepositoryStorage.java From archiva with Apache License 2.0 | 5 votes |
/** * FIXME remove * * @param href * @return */ private static String removePrefix(final String href) { String[] parts = StringUtils.split(href, '/'); parts = (String[]) ArrayUtils.subarray(parts, 1, parts.length); if (parts == null || parts.length == 0) { return "/"; } String joinedString = StringUtils.join(parts, '/'); if (href.endsWith("/")) { joinedString = joinedString + "/"; } return joinedString; }
Example 10
Source File: Encoder.java From PacketProxy with Apache License 2.0 | 5 votes |
/** * パケットのheadlineを返す。履歴ウィンドウで利用されます。 * 文字化けすると重たくなるのでデフォルトではASCIIで表示可能な部分のみ表示する */ public String getSummarizedRequest(Packet packet) { byte[] data = packet.getDecodedData(); byte[] prefix = ArrayUtils.subarray(data, 0, Math.min(100, data.length)); prefix = StringUtils.toAscii(prefix); return new String(prefix); }
Example 11
Source File: HttpProxy.java From vpn-over-dns with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void sendData(final byte data[]) throws IOException { // log.debug("sendData on id " + local_port); last_use = System.currentTimeMillis(); // log.debug("sendData(): " + data.length + " bytes"); if (closed) return; try { final ByteBuffer bb = ByteBuffer.allocate(to_socket_array.length + data.length); bb.put(to_socket_array); bb.put(data); bb.flip(); final int nbytes = socket_channel.write(bb); to_socket_array = ArrayUtils.subarray(bb.array(), nbytes, bb.array().length); } catch (final IOException ex) { log.warn(ex); ex.printStackTrace(); socket_channel.close(); closed = true; throw ex; } }
Example 12
Source File: CertificateUtils.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public static BigInteger obtainSerialNumber(PrivateKey key, byte[] challenge) throws TechnicalConnectorException { byte[] encryptedNonce = ArrayUtils.subarray(challenge, 0, challenge.length - 32); byte[] serialNrHashed = ArrayUtils.subarray(challenge, challenge.length - 32, challenge.length); byte[] decryptedNonceBytes = ConnectorCryptoUtils.decrypt(key, RaPropertiesLoader.getProperty("etk.challenge.cipher"), encryptedNonce); byte[] serialNr = ArrayUtils.subarray(decryptedNonceBytes, 0, 16); byte[] calculatedHash = ConnectorCryptoUtils.calculateDigest(RaPropertiesLoader.getProperty("etk.challenge.digest"), serialNr); if (!Arrays.equals(serialNrHashed, calculatedHash)) { throw new IllegalArgumentException("The challenge is not valid because the hash of the decrypted serial nr found inside the challenge is not equal to the hashed serial nr attached to the challenge."); } else { byte[] serialNumberUnsigned = new byte[serialNr.length + 1]; System.arraycopy(serialNr, 0, serialNumberUnsigned, 1, serialNr.length); return new BigInteger(serialNumberUnsigned); } }
Example 13
Source File: Signature.java From evt4j with MIT License | 5 votes |
/** * @param signatureBytes Signature in bytes * @return {@link Signature} */ public static Signature of(byte[] signatureBytes) { int recId = (int) signatureBytes[0] - 4 - 27; BigInteger r = new BigInteger(1, ArrayUtils.subarray(signatureBytes, 1, 33)); BigInteger s = new BigInteger(1, ArrayUtils.subarray(signatureBytes, 33, signatureBytes.length)); Signature sig = new Signature(r, s); sig.setRecId(recId); return sig; }
Example 14
Source File: Utils.java From evt4j with MIT License | 5 votes |
public static byte[] base58CheckDecode(String key, @Nullable String keyType) throws Base58CheckException { byte[] decoded; try { // base58 decode decoded = Base58.decode(key); } catch (AddressFormatException ex) { throw new Base58CheckException(ex.getMessage(), ex); } // split the byte slice byte[] data = ArrayUtils.subarray(decoded, 0, decoded.length - 4); byte[] checksum = ArrayUtils.subarray(decoded, decoded.length - 4, decoded.length); if (keyType != null) { data = ArrayUtils.addAll(data, keyType.getBytes()); } // ripemd160 input, sign 4 bytes to compare byte[] hash = ripemd160(data); // if pass, return data, otherwise throw ex // compare two checksum boolean isEqual = true; for (int i = 0; i < checksum.length; i++) { if (hash[i] != checksum[i]) { isEqual = false; } } if (!isEqual) { throw new Base58CheckException(); } if (keyType != null) { return ArrayUtils.subarray(data, 0, data.length - keyType.getBytes().length); } return data; }
Example 15
Source File: FooterGatherer.java From Bats with Apache License 2.0 | 5 votes |
private static void checkMagicBytes(FileStatus status, byte[] data, int offset) throws IOException { for(int i =0, v = offset; i < MAGIC_LENGTH; i++, v++){ if(ParquetFileWriter.MAGIC[i] != data[v]){ byte[] magic = ArrayUtils.subarray(data, offset, offset + MAGIC_LENGTH); throw new IOException(status.getPath() + " is not a Parquet file. expected magic number at tail " + Arrays.toString(ParquetFileWriter.MAGIC) + " but found " + Arrays.toString(magic)); } } }
Example 16
Source File: DesfireFile.java From MensaGuthaben with GNU General Public License v3.0 | 5 votes |
private RecordDesfireFile (int fileId, DesfireFileSettings fileSettings, byte[] fileData) { super(fileId, fileSettings, fileData); RecordDesfireFileSettings settings = (RecordDesfireFileSettings) fileSettings; DesfireRecord[] records = new DesfireRecord[settings.curRecords]; for (int i = 0; i < settings.curRecords; i++) { int offset = settings.recordSize * i; records[i] = new DesfireRecord(ArrayUtils.subarray(getData(), offset, offset + settings.recordSize)); } mRecords = records; }
Example 17
Source File: ChunkedDatasetV4.java From jhdf with MIT License | 4 votes |
@Override public int[] getChunkDimensions() { // TODO understand why there is an extra one on the end of this array int[] chunkDimensions = layoutMessage.getChunkDimensions(); return ArrayUtils.subarray(chunkDimensions, 0, chunkDimensions.length -1); }
Example 18
Source File: BinaryBuffer.java From PacketProxy with Apache License 2.0 | 4 votes |
public byte[] toByteArray() { return ArrayUtils.subarray(buffer, 0, data_size); }
Example 19
Source File: ValuePathHelper.java From cuba with Apache License 2.0 | 4 votes |
public static String pathPrefix(String[] elements) { String[] subPath = ArrayUtils.subarray(elements, 0, elements.length - 1); return ValuePathHelper.format(subPath); }
Example 20
Source File: TProtobufProcessor.java From jigsaw-payment with Apache License 2.0 | 4 votes |
private byte[] getValidBytes(ByteBuffer byteBuffer) { return ArrayUtils.subarray(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit()); }