List of usage examples for org.apache.commons.lang ArrayUtils addAll
public static double[] addAll(double[] array1, double[] array2)
Adds all the elements of the given arrays into a new array.
From source file:org.codice.ddf.libs.mpeg.transport.MpegTransportStreamMetadataExtractor.java
private void handleElementaryStreamPacket(final MTSPacket packet, final int packetId, final BiConsumer<Integer, byte[]> callback) { if (programElementaryStreams.containsKey(packetId)) { final PMTStream stream = programElementaryStreams.get(packetId); if (isMetadataStream(stream)) { final byte[] currentMetadataPacketBytes = currentMetadataPacketBytesByStream.get(packetId); final boolean startingNewMetadataPacket = packet.isPayloadUnitStartIndicator(); final boolean currentMetadataPacketToHandle = currentMetadataPacketBytes != null; final boolean reachedEndOfCurrentMetadataPacket = startingNewMetadataPacket && currentMetadataPacketToHandle; final byte[] payloadBytes = getByteBufferAsBytes(packet.getPayload()); if (reachedEndOfCurrentMetadataPacket) { callback.accept(packetId, currentMetadataPacketBytes); startNewMetadataPacketBytes(packetId, payloadBytes); } else if (startingNewMetadataPacket) { startNewMetadataPacketBytes(packetId, payloadBytes); } else if (currentMetadataPacketToHandle) { final byte[] concatenatedMetadataPacket = ArrayUtils.addAll(currentMetadataPacketBytes, payloadBytes);/*from w w w . j av a2 s.c o m*/ currentMetadataPacketBytesByStream.put(packetId, concatenatedMetadataPacket); } } } }
From source file:org.craftercms.search.service.impl.QueryParams.java
public QueryParams addParam(String name, String... values) { String[] oldValues = params.get(name); if (ArrayUtils.isNotEmpty(oldValues)) { values = (String[]) ArrayUtils.addAll(oldValues, values); }//from w w w . ja v a 2 s.co m params.put(name, values); return this; }
From source file:org.dawnsci.conversion.converters.CustomNCDConverter.java
private void exportASCII(IErrorDataset axis, Dataset data, IDataset errors, String fullName, String header, List<String> headings) throws ScanFileHolderException { String dataName = data.getName(); IDataset[] columns = new IDataset[] { DatasetUtils.transpose(data, null) }; if (axis != null) { if (axis.hasErrors()) { Dataset axisErrors = DatasetUtils.cast(axis.getError(), data.getDtype()); columns = (IDataset[]) ArrayUtils.addAll(new IDataset[] { axis, axisErrors }, columns); } else {// ww w . j a v a2 s . c om columns = (IDataset[]) ArrayUtils.addAll(new IDataset[] { axis }, columns); } } if (errors != null) { columns = (IDataset[]) ArrayUtils.addAll(columns, new IDataset[] { DatasetUtils.transpose(errors, null) }); } data = DatasetUtils.concatenate(columns, 1); data.setName(dataName); DataHolder dh = new DataHolder(); dh.addDataset(data.getName(), data); ASCIIDataWithHeadingSaver saver = new ASCIIDataWithHeadingSaver(fullName); saver.setCellFormat("%-12.8g"); saver.setHeader(header); saver.setHeadings(headings); saver.saveFile(dh); }
From source file:org.debux.webmotion.server.handler.ParametersExtractorHandler.java
@Override public void handle(Mapping mapping, Call call) { // Not action found in extension ? ActionRule actionRule = (ActionRule) call.getRule(); if (actionRule == null) { return;//from w w w.ja va 2 s . co m } // Contains all parameters Map<String, Object> rawParameters = call.getRawParameters(); // Add default parameters List<FilterRule> filterRules = call.getFilterRules(); for (FilterRule filterRule : filterRules) { Map<String, String[]> defaultParameters = filterRule.getDefaultParameters(); rawParameters.putAll(defaultParameters); } Map<String, String[]> defaultParameters = actionRule.getDefaultParameters(); rawParameters.putAll(defaultParameters); // Add extract parameters Map<String, Object> extractParameters = call.getExtractParameters(); rawParameters.putAll(extractParameters); // Retrieve the good name for parameters give in mapping HttpContext context = call.getContext(); String url = context.getUrl(); List<String> path = HttpUtils.splitPath(url); List<FragmentUrl> ruleUrl = actionRule.getRuleUrl(); int position = 0; for (FragmentUrl expression : ruleUrl) { String name = expression.getName(); if (!StringUtils.isEmpty(name)) { String value = path.get(position); String[] currentValues = (String[]) rawParameters.get(name); if (currentValues == null) { rawParameters.put(name, new String[] { value }); } else { rawParameters.put(name, ArrayUtils.add(currentValues, value)); } } position++; } List<FragmentUrl> ruleParameters = actionRule.getRuleParameters(); for (FragmentUrl expression : ruleParameters) { String name = expression.getName(); String param = expression.getParam(); if (!StringUtils.isEmpty(name)) { String[] values = (String[]) extractParameters.get(param); if (values != null) { String[] currentValues = (String[]) rawParameters.get(name); if (currentValues == null) { rawParameters.put(name, values); } else { rawParameters.put(name, ArrayUtils.addAll(currentValues, values)); } rawParameters.put(name + "." + param, values); } } } // Transform ParameterTree parameterTree = toTree(rawParameters); call.setParameterTree(parameterTree); }
From source file:org.debux.webmotion.server.handler.ParametersExtractorHandler.java
protected static ParameterTree toTree(Map<String, Object> parameters) { ParameterTree tree = new ParameterTree(); for (Map.Entry<String, Object> entry : parameters.entrySet()) { String paramName = entry.getKey(); Object paramValue = entry.getValue(); ParameterTree current = tree;// w w w .j ava 2s . c om Matcher matcher = pattern.matcher(paramName); while (matcher.find()) { String name = matcher.group(1); String index = matcher.group(3); ParameterTree next; if (index == null) { Map<String, ParameterTree> object = current.getObject(); if (object == null) { object = new HashMap<String, ParameterTree>(); current.setObject(object); } next = object.get(name); if (next == null) { next = new ParameterTree(); object.put(name, next); } } else { Map<String, List<ParameterTree>> array = current.getArray(); if (array == null) { array = new HashMap<String, List<ParameterTree>>(); current.setArray(array); } List<ParameterTree> list = array.get(name); if (list == null) { list = new ArrayList<ParameterTree>(); array.put(name, list); } int position = new Integer(index); if (position >= 0 && position < list.size()) { next = list.get(position); if (next == null) { next = new ParameterTree(); list.set(position, next); } } else { int fill = position - list.size(); for (int i = 0; i < fill; i++) { list.add(null); } next = new ParameterTree(); list.add(next); } } current = next; } if (paramValue != null) { if (paramValue.getClass().isArray()) { Object[] currentValues = (Object[]) current.getValue(); if (currentValues == null) { current.setValue(ArrayUtils.clone((Object[]) paramValue)); } else { current.setValue(ArrayUtils.addAll(currentValues, (Object[]) paramValue)); } } else { current.setValue(paramValue); } } } return tree; }
From source file:org.digidoc4j.impl.BDocContainerTest.java
static byte[] getExternalSignature(Container container, final X509Certificate signerCert, SignedInfo prepareSigningSignature, final DigestAlgorithm digestAlgorithm) { Signer externalSigner = new ExternalSigner(signerCert) { @Override/*from w w w .j ava2 s . c o m*/ public byte[] sign(Container container, byte[] dataToSign) { try { KeyStore keyStore = KeyStore.getInstance("PKCS12"); try (FileInputStream stream = new FileInputStream("testFiles/signout.p12")) { keyStore.load(stream, "test".toCharArray()); } PrivateKey privateKey = (PrivateKey) keyStore.getKey("1", "test".toCharArray()); final String javaSignatureAlgorithm = "NONEwith" + privateKey.getAlgorithm(); return DSSUtils.encrypt(javaSignatureAlgorithm, privateKey, addPadding(dataToSign)); } catch (Exception e) { throw new DigiDoc4JException("Loading private key failed"); } } private byte[] addPadding(byte[] digest) { byte[] signatureDigest; switch (digestAlgorithm) { case SHA512: signatureDigest = Constants.SHA512_DIGEST_INFO_PREFIX; break; case SHA256: signatureDigest = Constants.SHA256_DIGEST_INFO_PREFIX; break; default: throw new NotYetImplementedException(); } return ArrayUtils.addAll(signatureDigest, digest); } }; return externalSigner.sign(container, prepareSigningSignature.getDigest()); }
From source file:org.digidoc4j.signers.PKCS11SignatureToken.java
private static byte[] addPadding(byte[] digest, DigestAlgorithm digestAlgorithm) { return ArrayUtils.addAll(digestAlgorithm.digestInfoPrefix(), digest); // should find the prefix by checking digest length? }
From source file:org.dspace.content.DSpaceObjectServiceImpl.java
/** * Splits "schema.element.qualifier.language" into an array. * <p>//ww w. j a v a2 s . c om * The returned array will always have length greater than or equal to 4 * <p> * Values in the returned array can be empty or null. * @param fieldName field name * @return array */ protected String[] getElements(String fieldName) { String[] tokens = StringUtils.split(fieldName, "."); int add = 4 - tokens.length; if (add > 0) { tokens = (String[]) ArrayUtils.addAll(tokens, new String[add]); } return tokens; }
From source file:org.dspace.curate.CitationPage.java
/** * {@inheritDoc}//from w ww .j ava 2s . c o m * @see AbstractCurationTask#performItem(Item) */ @Override protected void performItem(Item item) throws SQLException { //Determine if the DISPLAY bundle exits. If not, create it. Bundle[] dBundles = item.getBundles(CitationPage.DISPLAY_BUNDLE_NAME); Bundle dBundle = null; if (dBundles == null || dBundles.length == 0) { try { dBundle = item.createBundle(CitationPage.DISPLAY_BUNDLE_NAME); } catch (AuthorizeException e) { log.error("User not authroized to create bundle on item \"" + item.getName() + "\": " + e.getMessage()); } } else { dBundle = dBundles[0]; } //Create a map of the bitstreams in the displayBundle. This is used to //check if the bundle being cited is already in the display bundle. Map<String, Bitstream> displayMap = new HashMap<String, Bitstream>(); for (Bitstream bs : dBundle.getBitstreams()) { displayMap.put(bs.getName(), bs); } //Determine if the preservation bundle exists and add it if we need to. //Also, set up bundles so it contains all ORIGINAL and PRESERVATION //bitstreams. Bundle[] pBundles = item.getBundles(CitationPage.PRESERVATION_BUNDLE_NAME); Bundle pBundle = null; Bundle[] bundles = null; if (pBundles != null && pBundles.length > 0) { pBundle = pBundles[0]; bundles = (Bundle[]) ArrayUtils.addAll(item.getBundles("ORIGINAL"), pBundles); } else { try { pBundle = item.createBundle(CitationPage.PRESERVATION_BUNDLE_NAME); } catch (AuthorizeException e) { log.error("User not authroized to create bundle on item \"" + item.getName() + "\": " + e.getMessage()); } bundles = item.getBundles("ORIGINAL"); } //Start looping through our bundles. Anything that is citable in these //bundles will be cited. for (Bundle bundle : bundles) { Bitstream[] bitstreams = bundle.getBitstreams(); // Loop through each file and generate a cover page for documents // that are PDFs. for (Bitstream bitstream : bitstreams) { BitstreamFormat format = bitstream.getFormat(); //If bitstream is a PDF document then it is citable. CitationDocument citationDocument = new CitationDocument(); if (citationDocument.canGenerateCitationVersion(bitstream)) { this.resBuilder.append(item.getHandle() + " - " + bitstream.getName() + " is citable."); try { //Create the cited document File citedDocument = citationDocument.makeCitedDocument(bitstream); //Add the cited document to the approiate bundle this.addCitedPageToItem(citedDocument, bundle, pBundle, dBundle, displayMap, item, bitstream); } catch (Exception e) { //Could be many things, but nothing that should be //expected. //Print out some detailed information for debugging. e.printStackTrace(); StackTraceElement[] stackTrace = e.getStackTrace(); StringBuilder stack = new StringBuilder(); int numLines = Math.min(stackTrace.length, 12); for (int j = 0; j < numLines; j++) { stack.append("\t" + stackTrace[j].toString() + "\n"); } if (stackTrace.length > numLines) { stack.append("\t. . .\n"); } log.error(e.toString() + " -> \n" + stack.toString()); this.resBuilder.append(", but there was an error generating the PDF.\n"); this.status = Curator.CURATE_ERROR; } } else { //bitstream is not a document this.resBuilder.append(item.getHandle() + " - " + bitstream.getName() + " is not citable.\n"); this.status = Curator.CURATE_SUCCESS; } } } }
From source file:org.dspace.servicemanager.DSpaceServiceManager.java
public void startup() { if (!testing) { // try to load up extra config files for spring String[] extraConfigs = configurationService.getPropertyAsType("service.manager.spring.configs", String[].class); if (extraConfigs != null) { if (springXmlConfigFiles == null) { springXmlConfigFiles = extraConfigs; } else { springXmlConfigFiles = (String[]) ArrayUtils.addAll(springXmlConfigFiles, extraConfigs); }//from w ww.j a v a 2 s . c om } } try { // have to put this at the top because otherwise initializing beans will die when they try to use the SMS this.running = true; // create the primary SMS and start it SpringServiceManager springSMS = new SpringServiceManager(this, configurationService, testing, developing, springXmlConfigFiles); try { springSMS.startup(); } catch (Exception e) { // startup failures are deadly throw new IllegalStateException("failure starting up spring service manager: " + e.getMessage(), e); } // add it to the list of service managers this.serviceManagers.add(springSMS); this.primaryServiceManager = springSMS; // now startup the activators registerActivators(); // now we call the ready mixins notifyServiceManagerReady(); } catch (Exception e) { shutdown(); // execute the shutdown String message = "Failed to startup the DSpace Service Manager: " + e.getMessage(); System.err.println(message); throw new RuntimeException(message, e); } }