List of usage examples for java.util Arrays copyOfRange
public static boolean[] copyOfRange(boolean[] original, int from, int to)
From source file:com.ibm.crail.tools.CrailFsck.java
public static void main(String[] args) throws Exception { String type = ""; String filename = "/tmp.dat"; long offset = 0; long length = 1; boolean randomize = false; int storageClass = 0; int locationClass = 0; Option typeOption = Option.builder("t").desc( "type of experiment [getLocations|directoryDump|namenodeDump|blockStatistics|ping|createDirectory]") .hasArg().build();// ww w .ja v a 2s . co m Option fileOption = Option.builder("f").desc("filename").hasArg().build(); Option offsetOption = Option.builder("y").desc("offset into the file").hasArg().build(); Option lengthOption = Option.builder("l").desc("length of the file [bytes]").hasArg().build(); Option storageOption = Option.builder("c").desc("storageClass for file [1..n]").hasArg().build(); Option locationOption = Option.builder("p").desc("locationClass for file [1..n]").hasArg().build(); Options options = new Options(); options.addOption(typeOption); options.addOption(fileOption); options.addOption(offsetOption); options.addOption(lengthOption); options.addOption(storageOption); options.addOption(locationOption); CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(options, Arrays.copyOfRange(args, 0, args.length)); if (line.hasOption(typeOption.getOpt())) { type = line.getOptionValue(typeOption.getOpt()); } if (line.hasOption(fileOption.getOpt())) { filename = line.getOptionValue(fileOption.getOpt()); } if (line.hasOption(offsetOption.getOpt())) { offset = Long.parseLong(line.getOptionValue(offsetOption.getOpt())); } if (line.hasOption(lengthOption.getOpt())) { length = Long.parseLong(line.getOptionValue(lengthOption.getOpt())); } if (line.hasOption(storageOption.getOpt())) { storageClass = Integer.parseInt(line.getOptionValue(storageOption.getOpt())); } if (line.hasOption(locationOption.getOpt())) { locationClass = Integer.parseInt(line.getOptionValue(locationOption.getOpt())); } CrailFsck fsck = new CrailFsck(); if (type.equals("getLocations")) { fsck.getLocations(filename, offset, length); } else if (type.equals("directoryDump")) { fsck.directoryDump(filename, randomize); } else if (type.equals("namenodeDump")) { fsck.namenodeDump(); } else if (type.equals("blockStatistics")) { fsck.blockStatistics(filename); } else if (type.equals("ping")) { fsck.ping(); } else if (type.equals("createDirectory")) { fsck.createDirectory(filename, storageClass, locationClass); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("crail fsck", options); System.exit(-1); } }
From source file:Main.java
public static byte[] getResponseData(byte[] response, int firstDataIndex, int datalength) { return Arrays.copyOfRange(response, firstDataIndex, firstDataIndex + datalength); }
From source file:Main.java
public static byte[] getMsgKeyHash(byte[] data) { byte[] msgKey = Arrays.copyOfRange(getSHA1hash(data), 4, 20); return msgKey; }
From source file:Main.java
public static byte[] getAuthKeyHash(byte[] key) { byte[] authKey = Arrays.copyOfRange(getSHA1hash(key), 12, 20); return authKey; }
From source file:Main.java
public static byte[] subRange(final byte[] bytes, int start, int length) { return Arrays.copyOfRange(bytes, start, start + length); }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T[][] dividirEn(T[] array, int pos, T[][] type) { Object[][] ret = { Arrays.copyOfRange(array, 0, pos), Arrays.copyOfRange(array, pos, array.length) }; return Arrays.asList(ret).toArray(type); }
From source file:Main.java
public static int[] offsetArray(int[] array, int offset) { int length = array.length; int moveLength = length - offset; int[] temp = Arrays.copyOfRange(array, moveLength, length); System.arraycopy(array, 0, array, offset, moveLength); System.arraycopy(temp, 0, array, 0, offset); return array; }
From source file:Main.java
public static byte[] trimLast(byte[] bytes) { int i = bytes.length - 1; for (; i >= 0; i--) { if (bytes[i] != 0) { break; }//from ww w.j ava 2s .co m } return Arrays.copyOfRange(bytes, 0, i + 1); }
From source file:Main.java
public static byte[] subByteArray(byte[] src, int startPos, int num) { int endPos = 0; if (startPos + num > src.length) { endPos = src.length;/* w w w.jav a 2 s. c om*/ } else { endPos = startPos + num; } return Arrays.copyOfRange(src, startPos, endPos); }
From source file:Main.java
/** * parse first frame buffer to retrieve file length * * @param fullFrame/*from www.j a v a 2s.c o m*/ * @return */ public static int getFileLength(byte[] fullFrame) { if (fullFrame.length > 6) { if (fullFrame[0] == 0x00 && fullFrame[1] == 0x00) { byte[] lengthBytes = Arrays.copyOfRange(fullFrame, 2, 6); int result = ((lengthBytes[3] & 0xFF) << 24) | ((lengthBytes[2] & 0xFF) << 16) | ((lengthBytes[1] & 0xFF) << 8) | ((lengthBytes[0] & 0xFF) << 0); return result; } else { return -1; } } return -1; }