本文整理汇总了Java中java.util.Arrays.copyOfRange方法的典型用法代码示例。如果您正苦于以下问题:Java Arrays.copyOfRange方法的具体用法?Java Arrays.copyOfRange怎么用?Java Arrays.copyOfRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Arrays
的用法示例。
在下文中一共展示了Arrays.copyOfRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserializeObjectInstances
import java.util.Arrays; //导入方法依赖的package包/类
private static List<LWM2MObjectInstance> deserializeObjectInstances(byte[] tlv, int offset, List<LWM2MObjectInstance> list) {
TypeIdLength til = TypeIdLength.createTypeIdLength(tlv, offset).deserialize();
offset = til.offset;
if (til.type == TYPE_OBJECT_INSTANCE) {
List<LWM2MResource> instances = new ArrayList<>();
byte[] nested = Arrays.copyOfRange(tlv, offset, offset + til.length);
deserializeResources(nested, 0, instances);
list.add (new LWM2MObjectInstance(LWM2MID.from(til.id), instances));
} else {
throw new IllegalArgumentException("Object instance is expected at index:" + offset);
}
offset += til.length;
return offset < tlv.length ? deserializeObjectInstances(tlv, offset, list) : list;
}
示例2: readPacketFromDevice
import java.util.Arrays; //导入方法依赖的package包/类
void readPacketFromDevice(FileInputStream inputStream, byte[] packet) throws DaedalusVpnService.VpnNetworkException, SocketException {
// Read the outgoing packet from the input stream.
int length;
try {
length = inputStream.read(packet);
} catch (IOException e) {
throw new DaedalusVpnService.VpnNetworkException("Cannot read from device", e);
}
if (length == 0) {
Log.w(TAG, "Got empty packet!");
return;
}
final byte[] readPacket = Arrays.copyOfRange(packet, 0, length);
handleDnsRequest(readPacket);
}
示例3: setCHR
import java.util.Arrays; //导入方法依赖的package包/类
@Override
protected void setCHR(byte[] chr){
if(chr.length>0){
CHRbanks = new byte[chr.length/0x1000][0x1000];
for(int i=0;i*0x1000<chr.length;i++)
CHRbanks[i]= Arrays.copyOfRange(chr, i*0x1000, (i*0x1000)+0x1000);
CHR_ROM[0]=CHRbanks[0];
CHR_ROM[1]=CHRbanks[1];
}
else{
CHR_ROM[0]= new byte[0x1000];
CHR_ROM[1]= new byte[0x1000];
CHR_ram = true;
}
smallchrrom = CHR_ram || CHRbanks.length==2;
}
示例4: setCHR
import java.util.Arrays; //导入方法依赖的package包/类
@Override
protected void setCHR(byte[] chr){
if(chr.length>0){
CHRbanks = new byte[chr.length/0x1000][0x1000];
for(int i=0;i*0x1000<chr.length;i++)
CHRbanks[i]= Arrays.copyOfRange(chr, i*0x1000, (i*0x1000)+0x1000);
CHR_ROM[0]=CHRbanks[0];
CHR_ROM[1]=CHRbanks[1];
}
else{
CHR_ROM[0]= new byte[0x1000];
CHR_ROM[1]= new byte[0x1000];
CHR_ram = true;
}
}
示例5: copyIVdata
import java.util.Arrays; //导入方法依赖的package包/类
private byte[] copyIVdata(byte[] keyData, int keyLength)
throws EncFSInvalidConfigException {
int ivLength = keyData.length - keyLength;
if (ivLength != IV_LENGTH_IN_BYTES) {
throw new EncFSInvalidConfigException("Non-standard IV length");
}
return Arrays.copyOfRange(keyData, keyLength, keyLength + ivLength);
}
示例6: decodeApicFrame
import java.util.Arrays; //导入方法依赖的package包/类
private static ApicFrame decodeApicFrame(ParsableByteArray id3Data, int frameSize,
int majorVersion) throws UnsupportedEncodingException {
int encoding = id3Data.readUnsignedByte();
String charset = getCharsetName(encoding);
byte[] data = new byte[frameSize - 1];
id3Data.readBytes(data, 0, frameSize - 1);
String mimeType;
int mimeTypeEndIndex;
if (majorVersion == 2) {
mimeTypeEndIndex = 2;
mimeType = "image/" + Util.toLowerInvariant(new String(data, 0, 3, "ISO-8859-1"));
if (mimeType.equals("image/jpg")) {
mimeType = "image/jpeg";
}
} else {
mimeTypeEndIndex = indexOfZeroByte(data, 0);
mimeType = Util.toLowerInvariant(new String(data, 0, mimeTypeEndIndex, "ISO-8859-1"));
if (mimeType.indexOf('/') == -1) {
mimeType = "image/" + mimeType;
}
}
int pictureType = data[mimeTypeEndIndex + 1] & 0xFF;
int descriptionStartIndex = mimeTypeEndIndex + 2;
int descriptionEndIndex = indexOfEos(data, descriptionStartIndex, encoding);
String description = new String(data, descriptionStartIndex,
descriptionEndIndex - descriptionStartIndex, charset);
int pictureDataStartIndex = descriptionEndIndex + delimiterLength(encoding);
byte[] pictureData = Arrays.copyOfRange(data, pictureDataStartIndex, data.length);
return new ApicFrame(mimeType, description, pictureType, pictureData);
}
示例7: getLevelData
import java.util.Arrays; //导入方法依赖的package包/类
public static String[] getLevelData(int level) {
initLevelsOffsets();
if (level < 1 || level > getLevelsCount()) {
return null;
} else {
return Arrays.copyOfRange(LEVELS_DATA, levelsOffsets.get(level - 1) + 1, levelsOffsets.get(level));
}
}
示例8: setPRG
import java.util.Arrays; //导入方法依赖的package包/类
@Override
protected void setPRG(byte[] prg){
PRG_ROM = new byte[4][0x2000];
PRGbanks = new byte[prg.length/0x2000][0x2000];
for(int i=0;i*0x2000<prg.length;i++){
PRGbanks[i]=Arrays.copyOfRange(prg, i*0x2000, (i*0x2000)+0x2000);
}
PRG_ROM[0]=PRGbanks[0];
PRG_ROM[1]=PRGbanks[1];
PRG_ROM[2]=PRGbanks[PRGbanks.length-2];
PRG_ROM[3]=PRGbanks[PRGbanks.length-1];
}
示例9: generate
import java.util.Arrays; //导入方法依赖的package包/类
/**
* Generate address from private key.
*
* @param keys private and public keys.
* @param seed seed.
* @param chain chain.
* @return address.
*/
private static Address generate(KeyPair keys, @Nullable final String seed, @NotNull final String chain) {
final byte[] privKey = keys.getPrivate().getEncoded();
final byte[] pubKey = keys.getPublic().getEncoded();
final byte[] hashPubKey = Arrays.copyOfRange(Crypto.hashChain(pubKey), 0, 20);
final byte[] unhashedAddress = ByteUtils.concat(new byte[]{(char) 1}, chain.getBytes(), hashPubKey);
final byte[] addressHash = Arrays.copyOfRange(Crypto.hashChain(unhashedAddress), 0, 4);
final String address = Base58.encode(ByteUtils.concat(unhashedAddress, addressHash));
final String publicKey = Base58.encode(pubKey);
final String privateKey = Base58.encode(privKey);
return createRaw(address, publicKey, privateKey, seed);
}
示例10: copyRange
import java.util.Arrays; //导入方法依赖的package包/类
public static byte[] copyRange(byte[] bytes,ByteRange range) {
if(range.a < 0) {
throw new ArrayIndexOutOfBoundsException("Range.a must be 0 or higher, was: " + range.a);
}
if(range.b > bytes.length) {
throw new ArrayIndexOutOfBoundsException("Range.b must be smaller then array length "+bytes.length+", was: " + range.b);
}
return Arrays.copyOfRange(bytes,range.a,range.b);
}
示例11: readBytes
import java.util.Arrays; //导入方法依赖的package包/类
byte[] readBytes(int offset, int len) throws NTLMException {
try {
return Arrays.copyOfRange(internal, offset, offset + len);
} catch (ArrayIndexOutOfBoundsException ex) {
throw new NTLMException(NTLMException.PACKET_READ_ERROR,
"Input message incorrect size");
}
}
示例12: Frame
import java.util.Arrays; //导入方法依赖的package包/类
/** Constructor: Receive data frame */
public Frame(byte[] frame) {
this.preamble = Arrays.copyOfRange(frame, 0, 1);
this.type = frame[2] >> 4;
this.id = 0x07 & frame[2];
this.typeId = frame[2];
this.dataLength = frame[3];
this.data = Arrays.copyOfRange(frame, 4, dataLength);
this.checksum = frame[36];
this.frame = frame;
}
示例13: processSelectFile
import java.util.Arrays; //导入方法依赖的package包/类
protected byte[] processSelectFile(final byte[] command) {
byte cla = command[0];
byte ins = command[1];
byte p1 = command[2];
byte p2 = command[3];
byte length = command[4];
byte[] aid = Arrays.copyOfRange(command, 5, 5+length);
if (Arrays.equals(aid, getAID())) {
return SUCCESS;
} else {
return FAIL_FILE_NOT_FOUND;
}
}
示例14: create
import java.util.Arrays; //导入方法依赖的package包/类
public static IpSeeker create(final byte[] buffer) {
//Head
final ByteBuffer headBuf = ByteBuffer.wrap(buffer, 0, 4 * 258);
final int headPos = headBuf.getInt();
// we have 256 segments, and last is the end position
final int[] segmentPos = new int[257];
for (int i = 0; i < 257; i++) {
segmentPos[i] = headBuf.getInt();
}
//Dict
final String dictRaw = new String(Arrays.copyOfRange(buffer, headPos, segmentPos[0]), UTF_8);
final String[] dict = StringUtil.splitc(dictRaw, '\001');
dict[0] = null; // "None" => null
//Segments
final int[][] segments = new int[256][];
final long[][] segmentIndexers = new long[256][];
for (int i = 0; i < 256; i++) {
int start = segmentPos[i];
int end = segmentPos[i + 1];
int len = (end - start) / 12; //(1 int + 1 long = 12 byte)
int[] segment = new int[len];
long[] segmentIndexer = new long[len];
ByteBuffer buf = ByteBuffer.wrap(buffer, start, end - start);
for (int j = 0; j < len; j++) {
segment[j] = buf.getInt();
segmentIndexer[j] = buf.getLong();
}
segments[i] = segment;
segmentIndexers[i] = segmentIndexer;
}
//XXX 校验
return new IpSeeker(dict, segments, segmentIndexers);
}
示例15: run
import java.util.Arrays; //导入方法依赖的package包/类
public int run(String[] args) throws Exception {
if (args.length < 2) {
System.err.println("HdfsWriter [local input path] [hdfs output path]");
return 1;
}
// Get the filename out of the file path
String filename = args[0].substring(args[0].lastIndexOf('/') + 1,args[0].length());
String dest = args[1];
// Create the destination path including the filename.
if (dest.charAt(dest.length() - 1) != '/') {
dest = dest + "/" + filename;
} else {
dest = dest + filename;
}
String localInputPath = args[0];
File inputPath = new File(localInputPath);
Path outputPath = new Path(dest);
if(!inputPath.exists()){
System.err.println("Input file does not exist!");
return 1;
}
Configuration conf = getConf();
System.out.println("configured filesystem = " + conf.get(FS_PARAM_NAME));
FileSystem fs = FileSystem.get(conf);
if (fs.exists(outputPath)) {
System.err.println("Output path exists!");
return 1;
}
InputStream is = new BufferedInputStream(new FileInputStream(localInputPath));
OutputStream os = fs.create(outputPath);
System.out.println("\nKuber encryption started!\n");
byte[] b = new byte[1024*100];
int numBytes = 0;
while ((numBytes = is.read(b)) > 0) {
byte[] block = Arrays.copyOfRange(b, 0, numBytes);
byte[] encrypted = encrypt(block);
os.write(encrypted, 0, numBytes);
}
is.close();
os.close();
return 0;
}