List of usage examples for java.util Arrays copyOfRange
public static boolean[] copyOfRange(boolean[] original, int from, int to)
From source file:example.SimpleChaincode.java
private Response invoke(ChaincodeStub stub, String[] args) { System.out.println("ENTER invoke with args: " + Arrays.toString(args)); if (args.length < 2) throw new IllegalArgumentException( "Incorrect number of arguments. Expecting at least 2, got " + args.length); final String subFunction = args[0]; final String[] subArgs = Arrays.copyOfRange(args, 1, args.length); switch (subFunction) { case "move": return transfer(stub, subArgs); case "query": return query(stub, subArgs); case "delete": for (String arg : args) stub.delState(arg);//from ww w. j a va 2s . c om return newSuccessResponse(); default: return newBadRequestResponse(newErrorJson("Unknown invoke sub-function: %s", subFunction)); } }
From source file:edu.harvard.hms.dbmi.bd2k.irct.ri.i2b2transmart.I2B2TranSMARTResourceImplementation.java
@Override public List<Entity> getPathRelationship(Entity path, OntologyRelationship relationship, SecureSession session) throws ResourceInterfaceException { List<Entity> returns = super.getPathRelationship(path, relationship, session); // Get the counts from the tranSMART server try {//from ww w.j a va 2s . com HttpClient client = createClient(session); String basePath = path.getPui(); String[] pathComponents = basePath.split("/"); if (pathComponents.length > 3) { String myPath = "\\"; for (String pathComponent : Arrays.copyOfRange(pathComponents, 3, pathComponents.length)) { myPath += "\\" + pathComponent; } basePath = pathComponents[0] + "/" + pathComponents[1] + "/" + pathComponents[2]; HttpPost post = new HttpPost(this.transmartURL + "/chart/childConceptPatientCounts"); List<NameValuePair> formParameters = new ArrayList<NameValuePair>(); formParameters.add(new BasicNameValuePair("charttype", "childconceptpatientcounts")); formParameters.add(new BasicNameValuePair("concept_key", myPath + "\\")); formParameters.add(new BasicNameValuePair("concept_level", "")); post.setEntity(new UrlEncodedFormEntity(formParameters)); HttpResponse response = client.execute(post); JsonReader jsonReader = Json.createReader(response.getEntity().getContent()); JsonObject counts = jsonReader.readObject().getJsonObject("counts"); for (Entity singleReturn : returns) { String singleReturnMyPath = convertPUItoI2B2Path(singleReturn.getPui()); if (counts.containsKey(singleReturnMyPath)) { singleReturn.getCounts().put("count", counts.getInt(singleReturnMyPath)); } } } } catch (IOException e) { e.printStackTrace(); } return returns; }
From source file:com.dsh105.commodus.StringUtil.java
/** * Builds a sentence list from an array of strings. * Example: {"one", "two", "three"} returns "one, two and three". * * @param words The string array to build into a list, * @return String representing the list. *///w w w. ja v a 2 s . co m public static String buildSentenceList(String... words) { Validate.notEmpty(words); if (words.length == 1) { return words[0]; } else if (words.length == 2) { return combineArray(0, " and ", words); } else { // This is where the fun starts! String[] initial = Arrays.copyOfRange(words, 0, words.length - 1); String list = combineArray(0, ", ", initial); list += " and " + words[words.length - 1]; return list; } }
From source file:com.redblackit.web.server.EchoServletTest.java
/** * Constructor taking test values//from w ww. ja v a 2 s . c om * * @param requestURI * @param headers * @param body */ public EchoServletTest(String requestURI, String[][] headers, String body) { this.echoServlet = new EchoServlet(); this.requestURI = requestURI; this.headersMap = new TreeMap<String, List<String>>(); if (headers != null && headers.length > 0) { logger.debug("<init>:headers=" + Arrays.deepToString(headers)); int hi = 0; for (String[] header : headers) { logger.debug("<init>:header[" + hi + "]=" + Arrays.toString(header)); if (header != null && header.length > 0) { String[] values; if (header.length > 1) { values = Arrays.copyOfRange(header, 1, header.length); logger.debug("<init>:header[" + hi + "].values=" + Arrays.toString(values)); } else { values = new String[] { "" }; logger.debug("<init>:header[" + hi + "].values=" + Arrays.toString(values) + "(empty)"); } headersMap.put(header[0], Arrays.asList(values)); } } } this.body = body; }
From source file:com.netflix.imfutility.ttmltostl.stl.StlTtiTest.java
@Test public void testSimpleTti() throws Exception { TimedTextObject tto = StlTestUtil.buildTto("10:00:00:00", "10:00:05:00", "text1", "10:00:05:00", "10:00:10:12", "text2", "10:04:59:00", "23:59:59:24", "text3"); byte[][] stl = StlTestUtil.build(tto, StlTestUtil.getMetadataXml()); byte[] tti = stl[1]; // 1st block: information int offset = 128; // subtitle zero assertArrayEquals(new byte[] { 0x00, // group number - 0 0x01, 0x00, // subtitle number - 1 (byte) 0xff, // extension block - default 0x00, // cumulative status - 00 (no cumulative) 0x0a, 0x00, 0x00, 0x00, // code in: 10:00:00:00 0x0a, 0x00, 0x05, 0x00, // code out: 10:00:05:00 0x16, // vertical position 0x02, // centered by default 0x00, // comment - 00 (contains subtitle) }, Arrays.copyOfRange(tti, offset, offset + 16)); // 1st block: text assertArrayEquals(fillExpectedText(new byte[] { 0x74, 0x65, 0x78, 0x74, 0x31 }), Arrays.copyOfRange(tti, offset + 16, offset + 128)); // 2d block: information offset += 128;// ww w . ja v a 2 s . com assertArrayEquals(new byte[] { 0x00, // group number - 0 0x02, 0x00, // subtitle number - 2 (byte) 0xff, // extension block - default 0x00, // cumulative status - 00 (no cumulative) 0x0a, 0x00, 0x05, 0x00, // code in: 10:00:05:00 0x0a, 0x00, 0x0a, 0x0c, // code out: 10:00:10:12 0x16, // vertical position 0x02, // centered by default 0x00, // comment - 00 (contains subtitle) }, Arrays.copyOfRange(tti, offset, offset + 16)); // 2d block: text assertArrayEquals(fillExpectedText(new byte[] { 0x74, 0x65, 0x78, 0x74, 0x32 }), Arrays.copyOfRange(tti, offset + 16, offset + 128)); // 3d block: information offset += 128; assertArrayEquals(new byte[] { 0x00, // group number - 0 0x03, 0x00, // subtitle number - 3 (byte) 0xff, // extension block - default 0x00, // cumulative status - 00 (no cumulative) 0x0a, 0x04, 0x3b, 0x00, // code in: 10:04:59:00 0x17, 0x3b, 0x3b, 0x18, // code out: 23:59:59:24 0x16, // vertical position 0x02, // centered by default 0x00, // comment - 00 (contains subtitle) }, Arrays.copyOfRange(tti, offset, offset + 16)); // 3d block: text assertArrayEquals(fillExpectedText(new byte[] { 0x74, 0x65, 0x78, 0x74, 0x33 }), Arrays.copyOfRange(tti, offset + 16, offset + 128)); }
From source file:gobblin.cli.Cli.java
/** * Parse and execute the appropriate command based on the args. * The general flow looks like this:/*from w ww. ja va2s. co m*/ * * 1. Parse a set of global options (eg host/port for the admin server) * 2. Parse out the command name * 3. Pass the global options and any left over parameters to a command handler */ public void parseAndExecuteCommand() { CommandLineParser parser = new DefaultParser(); try { CommandLine parsedOpts = parser.parse(this.options, this.args, true); GlobalOptions globalOptions = createGlobalOptions(parsedOpts); // Fetch the command and fail if there is ambiguity String[] remainingArgs = parsedOpts.getArgs(); if (remainingArgs.length == 0) { printHelpAndExit("Command not specified!"); } String commandName = remainingArgs[0].toLowerCase(); remainingArgs = remainingArgs.length > 1 ? Arrays.copyOfRange(remainingArgs, 1, remainingArgs.length) : new String[] {}; Command command = commandList.get(commandName); if (command == null) { System.out.println("Command " + commandName + " not known."); printHelpAndExit(); } else { command.execute(globalOptions, remainingArgs); } } catch (ParseException e) { printHelpAndExit("Ran into an error parsing args."); } }
From source file:gobblin.source.extractor.extract.kafka.KafkaAvroExtractor.java
@Override protected GenericRecord decodeRecord(MessageAndOffset messageAndOffset) throws SchemaNotFoundException, IOException { byte[] payload = getBytes(messageAndOffset.message().payload()); if (payload[0] != KafkaAvroSchemaRegistry.MAGIC_BYTE) { throw new RuntimeException( String.format("Unknown magic byte for partition %s", this.getCurrentPartition())); }/*w ww . ja v a 2s . c om*/ byte[] schemaIdByteArray = Arrays.copyOfRange(payload, 1, 1 + KafkaAvroSchemaRegistry.SCHEMA_ID_LENGTH_BYTE); String schemaId = Hex.encodeHexString(schemaIdByteArray); Schema schema = null; schema = this.schemaRegistry.getSchemaById(schemaId); reader.get().setSchema(schema); Decoder binaryDecoder = DecoderFactory.get().binaryDecoder(payload, 1 + KafkaAvroSchemaRegistry.SCHEMA_ID_LENGTH_BYTE, payload.length - 1 - KafkaAvroSchemaRegistry.SCHEMA_ID_LENGTH_BYTE, null); try { GenericRecord record = reader.get().read(null, binaryDecoder); if (!record.getSchema().equals(this.schema.get())) { record = AvroUtils.convertRecordSchema(record, this.schema.get()); } return record; } catch (IOException e) { LOG.error(String.format("Error during decoding record for partition %s: ", this.getCurrentPartition())); throw e; } }
From source file:com.addthis.hydra.data.util.FindChangePoints.java
private static List<ChangePoint> findAndSmoothOverPeaks(Long[] data, int minChange, double minZscore, int width) { ArrayList<ChangePoint> rvList = new ArrayList<>(); for (int i = 0; i < data.length; i++) { int leftEndpoint = Math.max(0, i - width); int rightEndpoint = Math.min(i + width, data.length); Long[] neighborhood = Arrays.copyOfRange(data, leftEndpoint, rightEndpoint); Long[] neighborhoodWithout = ArrayUtils.addAll(Arrays.copyOfRange(data, leftEndpoint, i), Arrays.copyOfRange(data, i + 1, rightEndpoint)); if (sd(neighborhood) > minZscore * sd(neighborhoodWithout)) { double change = data[i] - mean(neighborhoodWithout); if (Math.abs(change) > minChange) { rvList.add(new ChangePoint((int) change, i, ChangePoint.ChangePointType.PEAK)); data[i] = (long) mean(neighborhoodWithout); }/* ww w.j av a2s .co m*/ } } return rvList; }
From source file:com.alliander.osgp.shared.security.EncryptionService.java
/** * Decrypts the data using the key, Strips off iv bytes when they are there * (first 16 0 bytes).//from w ww. j a va2s .c o m */ public byte[] decrypt(final byte[] inputData) { try { final Cipher cipher = Cipher.getInstance(ALGORITHM, PROVIDER); cipher.init(Cipher.DECRYPT_MODE, this.key, new IvParameterSpec(IVBYTES)); final byte[] decryptedData = cipher.doFinal(inputData); if (this.checkNullBytesPrepended(decryptedData)) { return Arrays.copyOfRange(decryptedData, IVBYTES.length, decryptedData.length); } else { return decryptedData; } } catch (final NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException | NoSuchProviderException | InvalidAlgorithmParameterException ex) { LOGGER.error(UNEXPECTED_EXCEPTION_DURING_DECRYPTION, ex); throw new EncrypterException("Unexpected exception during decryption!", ex); } }
From source file:my.adam.smo.common.SymmetricEncryptionBox.java
public byte[] decrypt(byte[] cryptogram, byte[] key) { if (key.length != 32) { throw new IllegalArgumentException("key have to be 16 bytes long (32 bits)"); }/* ww w . jav a 2s . com*/ byte[] out = Arrays.copyOfRange(cryptogram, ivLength, cryptogram.length); CipherParameters cp = new ParametersWithIV(new KeyParameter(key), getIV(cryptogram)); PaddedBufferedBlockCipher descCipher; descCipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), new PKCS7Padding()); descCipher.init(false, cp); descCipher.processBytes(cryptogram, ivLength, cryptogram.length - ivLength, out, 0); return getMessageWithoutSeed(out); }