List of usage examples for java.util Arrays copyOf
public static boolean[] copyOf(boolean[] original, int newLength)
From source file:interactivespaces.util.sampling.SampledDataSequencePlayer.java
/** * Play the frames in sequence.//from w w w.j a va2 s . com * * @throws InterruptedException * the player has been interrupted */ private void play() throws InterruptedException { List<SampledDataFrame> frames = sequence.getFrames(); int maxFrames = frames.size() - 1; while (!Thread.interrupted()) { log.info("Starting playback of sampled data"); SampledDataFrame currentFrame = frames.get(0); int[] samples = currentFrame.getSamples(); sender.sendSampledData(currentFrame.getSource(), Arrays.copyOf(samples, samples.length)); SampledDataFrame previousFrame; for (int frame = 1; !Thread.interrupted() && frame < maxFrames; frame++) { previousFrame = currentFrame; currentFrame = frames.get(frame); long delay = currentFrame.getTimestamp() - previousFrame.getTimestamp(); if (delay > 0) { Thread.sleep(delay); } samples = currentFrame.getSamples(); sender.sendSampledData(currentFrame.getSource(), Arrays.copyOf(samples, samples.length)); } log.info("Ending playback of sampled data"); } }
From source file:candr.yoclip.option.OptionField.java
/** * Get the names associated with the option. * * @return the option names as a string array or an empty array if the option does not have a name associated with * it.//from w w w. j a v a 2 s. c o m */ @Override public String[] getNames() { return Arrays.copyOf(option.name(), option.name().length); }
From source file:com.opengamma.analytics.math.function.RealPolynomialFunction1D.java
/** * Adds a constant to the polynomial (equivalent to adding the value to the constant term of the polynomial). The result is * also a polynomial./*from w w w . jav a 2 s . co m*/ * @param a The value to add * @return $P+a$ */ @Override public RealPolynomialFunction1D add(final double a) { final double[] c = Arrays.copyOf(getCoefficients(), _n); c[0] += a; return new RealPolynomialFunction1D(c); }
From source file:com.google.identitytoolkit.GitkitUser.java
public GitkitUser setHash(byte[] hash) { this.hash = Arrays.copyOf(hash, hash.length); return this; }
From source file:net.ftb.util.CryptoUtils.java
/** * method to pad AES keys by using the sha1Hex hash on them * @param key key to pad// www . jav a 2 s .c o m * @return padded key */ public static byte[] pad(byte[] key) { try { return Arrays.copyOf(DigestUtils.sha1Hex(key).getBytes("utf8"), 16); } catch (UnsupportedEncodingException e) { Logger.logError("error encoding padded key!", e); return Arrays.copyOf(DigestUtils.sha1Hex(key).getBytes(), 16); } }
From source file:com.google.nigori.server.appengine.AEUser.java
@Override public byte[] getPublicKey() { byte[] pkB = publicKey.getBytes(); return Arrays.copyOf(pkB, pkB.length); }
From source file:com.netflix.hystrix.contrib.javanica.command.GenericCommand.java
/** * The fallback is performed whenever a command execution fails. * Also a fallback method will be invoked within separate command in the case if fallback method was annotated with * HystrixCommand annotation, otherwise current implementation throws RuntimeException and leaves the caller to deal with it * (see {@link super#getFallback()}).//from ww w .j a v a 2 s . co m * The getFallback() is always processed synchronously. * Since getFallback() can throw only runtime exceptions thus any exceptions are thrown within getFallback() method * are wrapped in {@link FallbackInvocationException}. * A caller gets {@link com.netflix.hystrix.exception.HystrixRuntimeException} * and should call getCause to get original exception that was thrown in getFallback(). * * @return result of invocation of fallback method or RuntimeException */ @Override protected Object getFallback() { if (getFallbackAction() != null) { final CommandAction commandAction = getFallbackAction(); try { return process(new Action() { @Override Object execute() { Object[] args = commandAction.getMetaHolder().getArgs(); if (commandAction.getMetaHolder().isExtendedFallback()) { if (commandAction.getMetaHolder().isExtendedParentFallback()) { args[args.length - 1] = getFailedExecutionException(); } else { args = Arrays.copyOf(args, args.length + 1); args[args.length - 1] = getFailedExecutionException(); } } else { if (commandAction.getMetaHolder().isExtendedParentFallback()) { args = ArrayUtils.remove(args, args.length - 1); } } return commandAction .executeWithArgs(commandAction.getMetaHolder().getFallbackExecutionType(), args); } }); } catch (Throwable e) { LOGGER.error(FallbackErrorMessageBuilder.create().append(commandAction, e).build()); throw new FallbackInvocationException(e.getCause()); } } else { return super.getFallback(); } }
From source file:com.netflix.hystrix.contrib.javanica.utils.MethodProvider.java
/** * Gets fallback method for command method. * * @param type type// w w w . j a v a 2s. c o m * @param commandMethod the command method. in the essence it can be a fallback * method annotated with HystrixCommand annotation that has a fallback as well. * @param extended true if the given commandMethod was derived using additional parameter, otherwise - false * @return new instance of {@link FallbackMethod} or {@link FallbackMethod#ABSENT} if there is no suitable fallback method for the given command */ public FallbackMethod getFallbackMethod(Class<?> type, Method commandMethod, boolean extended) { if (commandMethod.isAnnotationPresent(HystrixCommand.class)) { HystrixCommand hystrixCommand = commandMethod.getAnnotation(HystrixCommand.class); if (StringUtils.isNotBlank(hystrixCommand.fallbackMethod())) { Class<?>[] parameterTypes = commandMethod.getParameterTypes(); if (extended && parameterTypes[parameterTypes.length - 1] == Throwable.class) { parameterTypes = ArrayUtils.remove(parameterTypes, parameterTypes.length - 1); } Class<?>[] exParameterTypes = Arrays.copyOf(parameterTypes, parameterTypes.length + 1); exParameterTypes[parameterTypes.length] = Throwable.class; Optional<Method> exFallbackMethod = getMethod(type, hystrixCommand.fallbackMethod(), exParameterTypes); Optional<Method> fMethod = getMethod(type, hystrixCommand.fallbackMethod(), parameterTypes); Method method = exFallbackMethod.or(fMethod).orNull(); if (method == null) { throw new FallbackDefinitionException("fallback method wasn't found: " + hystrixCommand.fallbackMethod() + "(" + Arrays.toString(parameterTypes) + ")"); } return new FallbackMethod(method, exFallbackMethod.isPresent()); } } return FallbackMethod.ABSENT; }
From source file:com.orange.clara.cloud.servicedbdumper.filer.s3uploader.UploadS3StreamImpl.java
@Override public String upload(InputStream content, Blob blob) throws IOException { String key = blob.getMetadata().getName(); String bucketName = this.blobStoreContext.getBucketName(); ContentMetadata metadata = blob.getMetadata().getContentMetadata(); ObjectMetadataBuilder builder = ObjectMetadataBuilder.create().key(key) .contentType(MediaType.OCTET_STREAM.toString()).contentDisposition(key) .contentEncoding(metadata.getContentEncoding()).contentLanguage(metadata.getContentLanguage()) .userMetadata(blob.getMetadata().getUserMetadata()); String uploadId = this.s3Client.initiateMultipartUpload(bucketName, builder.build()); Integer partNum = 1;//from w w w . j a v a 2 s . co m Payload part = null; int bytesRead = 0; byte[] chunk = null; boolean shouldContinue = true; SortedMap<Integer, String> etags = Maps.newTreeMap(); try { while (shouldContinue) { chunk = new byte[chunkSize]; bytesRead = ByteStreams.read(content, chunk, 0, chunk.length); if (bytesRead != chunk.length) { shouldContinue = false; chunk = Arrays.copyOf(chunk, bytesRead); if (chunk.length == 0) { //something from jvm causing memory leak, we try to help jvm which seems working. //but PLEASE DON'T REPLICATE AT HOME ! chunk = null; part = null; System.gc(); // break; } } part = new ByteArrayPayload(chunk); prepareUploadPart(bucketName, key, uploadId, partNum, part, etags); partNum++; //something from jvm causing memory leak, we try to help jvm which seems working. //but PLEASE DON'T REPLICATE AT HOME ! chunk = null; part = null; System.gc(); // } return this.completeMultipartUpload(bucketName, key, uploadId, etags); } catch (RuntimeException ex) { this.s3Client.abortMultipartUpload(bucketName, key, uploadId); throw ex; } }
From source file:com.waveerp.desEncryption.java
public void Encrypter(String keyString, String ivString) { try {/* ww w . ja va 2s . c o m*/ keyString = "J3SuSChRiSt"; ivString = "Pr0V3rBs"; final MessageDigest msgDigest = MessageDigest.getInstance("md5"); final byte[] digestOfPassword = msgDigest.digest(Base64.decodeBase64(keyString.getBytes("utf-8"))); final byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); for (int j = 0, k = 16; j < 8;) { keyBytes[k++] = keyBytes[j++]; } kSpec = new DESedeKeySpec(keyBytes); sKey = SecretKeyFactory.getInstance("DESede").generateSecret(kSpec); ivParSpec = new IvParameterSpec(ivString.getBytes()); } catch (Exception e) { e.printStackTrace(); } }