List of usage examples for org.apache.commons.lang ArrayUtils subarray
public static boolean[] subarray(boolean[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new boolean
array containing the elements between the start and end indices.
From source file:com.haulmont.cuba.gui.data.impl.AbstractCollectionDatasource.java
protected Map<String, Object> getQueryParameters(Map<String, Object> params) { final Map<String, Object> map = new HashMap<>(); for (ParameterInfo info : queryParameters) { String name = info.getFlatName(); final String path = info.getPath(); final String[] elements = path.split("\\."); switch (info.getType()) { case DATASOURCE: { String dsName = elements[0]; final Datasource datasource = dsContext.get(dsName); if (datasource == null) { throw new DevelopmentException("Datasource '" + dsName + "' not found in dsContext", "datasource", dsName); }// w w w .j av a 2 s .c o m if (datasource.getState() == State.VALID) { final Entity item = datasource.getItem(); if (elements.length > 1) { String[] valuePath = (String[]) ArrayUtils.subarray(elements, 1, elements.length); String propertyName = InstanceUtils.formatValuePath(valuePath); Object value = InstanceUtils.getValueEx(item, propertyName); map.put(name, value); } else { map.put(name, item); } } else { map.put(name, null); } break; } case PARAM: { Object value; if (dsContext.getFrameContext() == null) { value = null; } else { Map<String, Object> windowParams = dsContext.getFrameContext().getParams(); value = windowParams.get(path); if (value == null && elements.length > 1) { Instance instance = (Instance) windowParams.get(elements[0]); if (instance != null) { String[] valuePath = (String[]) ArrayUtils.subarray(elements, 1, elements.length); String propertyName = InstanceUtils.formatValuePath(valuePath); value = InstanceUtils.getValueEx(instance, propertyName); } } } if (value instanceof String && info.isCaseInsensitive()) { value = makeCaseInsensitive((String) value); } map.put(name, value); break; } case COMPONENT: { Object value = null; if (dsContext.getFrameContext() != null) { value = dsContext.getFrameContext().getValue(path); if (value instanceof String && info.isCaseInsensitive()) { value = makeCaseInsensitive((String) value); } if (java.sql.Date.class.equals(info.getJavaClass()) && value != null && value instanceof Date) { value = new java.sql.Date(((Date) value).getTime()); } if (refreshOnComponentValueChange) { if (componentValueListener == null) componentValueListener = new ComponentValueListener(); try { dsContext.getFrameContext().addValueChangeListener(path, componentValueListener); } catch (Exception e) { Logger log = LoggerFactory.getLogger(AbstractCollectionDatasource.class); log.error("Unable to add value listener: " + e); } } } map.put(name, value); break; } case SESSION: { Object value; value = userSession.getAttribute(path); if (value instanceof String && info.isCaseInsensitive()) { value = makeCaseInsensitive((String) value); } map.put(name, value); break; } case CUSTOM: { Object value = params.get(info.getPath()); if (value == null) { //a case when a query contains a parameter like :custom$city.country.id and we passed //just "city" parameter to the datasource refresh() method String[] pathElements = info.getPath().split("\\."); if (pathElements.length > 1) { Object entity = params.get(pathElements[0]); if (entity != null && entity instanceof Instance) { value = InstanceUtils.getValueEx((Instance) entity, Arrays.copyOfRange(pathElements, 1, pathElements.length)); } } } if (value instanceof String && info.isCaseInsensitive()) { value = makeCaseInsensitive((String) value); } map.put(name, value); break; } default: { throw new UnsupportedOperationException("Unsupported parameter type: " + info.getType()); } } } return map; }
From source file:edu.utdallas.bigsecret.crypter.CrypterMode3.java
/** * {@inheritDoc}//from ww w .j ava2 s .co m */ public byte[] unwrapQualifier(byte[] row, byte[] family, byte[] qualifier, long ts, byte[] value) throws Exception { if (qualifier == null || qualifier.length == 0) throw new Exception("Qualifier data null or no data"); byte[] completeData = m_keyCipher.decrypt(qualifier); int rowSize = Bytes.toInt(completeData, 0, 4); int famSize = Bytes.toInt(completeData, 4, 4); int quaSize = Bytes.toInt(completeData, 8, 4); return ArrayUtils.subarray(completeData, 12 + rowSize + famSize, 12 + rowSize + famSize + quaSize); }
From source file:net.nperkins.quizmaster3000.QuizMaster3000.java
/** * Load questions from a quizfile//from ww w. j a v a2 s .c o m * * @param quizfilepath File path of quizfile * @throws IOException */ private void loadQuestions(String quizfilepath) throws IOException { BufferedReader br = new BufferedReader(new FileReader(quizfilepath)); String line; while ((line = br.readLine()) != null) { Question thisLine = new Question(); String[] splitLine = line.split("\\|"); if (splitLine.length < 2) { getLogger().info(prefixMessage(messages.getString("error.invalidquestion"))); continue; } thisLine.setQuestion(splitLine[0]); thisLine.setAnswer((String[]) ArrayUtils.subarray(splitLine, 1, splitLine.length)); questions.add(thisLine); } br.close(); }
From source file:edu.utdallas.bigsecret.crypter.CrypterMode1.java
/** * {@inheritDoc}/*from w w w. j av a 2 s . co m*/ */ public byte[] unwrapFamily(byte[] row, byte[] family, byte[] qualifier, long ts, byte[] value) throws Exception { if (qualifier == null || qualifier.length == 0) throw new Exception("Qualifier data null or no data"); int qualifierIndexSize = getIndexQualifierDataSize(); byte[] completeData = m_keyCipher.decrypt(qualifier, qualifierIndexSize); int rowSize = Bytes.toInt(completeData, 0, 4); int famSize = Bytes.toInt(completeData, 4, 4); return ArrayUtils.subarray(completeData, 12 + rowSize, 12 + rowSize + famSize); }
From source file:com.tesora.dve.mysqlapi.repl.MyReplicationVisitorDispatch.java
@Override public void visit(MyExecuteLoadLogEvent packet) throws PEException { boolean switchToDb = true; ServerDBConnection conn = null;//from w ww . j a v a2s . com String dbName = packet.getDbName(); String origQuery = packet.getOrigQuery(); try { if (!this.includeDatabase(plugin, dbName)) { // still want to update log position if we filter out message updateBinLogPosition(packet, plugin); return; } conn = plugin.getServerDBConnection(); // If any session variables are to be set do it first plugin.getSessionVariableCache().setAllSessionVariableValues(conn); if (logger.isDebugEnabled()) { logger.debug("** START ExecuteLoadLog Event **"); if (switchToDb) logger.debug("USE " + dbName); logger.debug(origQuery); logger.debug("** END ExecuteLoadLog Event **"); } if (switchToDb) conn.setCatalog(dbName); // since we don't want to parse here to determine if a time function is specified // set the TIMESTAMP variable to the master statement execution time conn.executeUpdate("set " + VariableConstants.REPL_SLAVE_TIMESTAMP_NAME + "=" + packet.getCommonHeader().getTimestamp()); executeLDR(conn, plugin.getClientConnectionContext().getCtx(), origQuery.getBytes(CharsetUtil.UTF_8)); // start throwing down the bytes from the load data infile File infile = plugin.getInfileHandler().getInfile(packet.getFileId()); FileInputStream in = null; byte[] readData = new byte[MyExecuteLoadLogEvent.MAX_BUFFER_LEN]; try { in = new FileInputStream(infile); int len = in.read(readData); do { final byte[] readData1 = (len == MyExecuteLoadLogEvent.MAX_BUFFER_LEN) ? readData : ArrayUtils.subarray(readData, 0, len); executeLDB(conn, plugin.getClientConnectionContext().getCtx(), readData1); len = in.read(readData); } while (len > -1); executeLDB(conn, plugin.getClientConnectionContext().getCtx(), ArrayUtils.EMPTY_BYTE_ARRAY); } finally { IOUtils.closeQuietly(in); plugin.getInfileHandler().cleanUp(); } updateBinLogPosition(packet, plugin); } catch (Exception e) { if (plugin.validateErrorAndStop(packet.getErrorCode(), e)) { logger.error("Error occurred during replication processing: ", e); try { conn.execute("ROLLBACK"); } catch (SQLException e1) { throw new PEException("Error attempting to rollback after exception", e); // NOPMD by doug on 18/12/12 8:07 AM } } else { packet.setSkipErrors(true, "Replication Slave failed processing: '" + origQuery + "' but slave_skip_errors is active. Replication processing will continue"); } throw new PEException("Error executing: " + origQuery, e); } finally { // NOPMD by doug on 18/12/12 8:08 AM // Clear all the session variables since they are only good for one // event plugin.getSessionVariableCache().clearAllSessionVariables(); } }
From source file:com.mg.framework.service.DatabaseAuditServiceImpl.java
public void auditModify(PostUpdateEvent modifyEvent) { if (!isAuditActivated) return;// w w w.j a va 2s . co m try { List<Integer> auditedList; String[] names; Lock lock = entityAuditSetupLock.readLock(); lock.lock(); try { EntityAuditSetup auditSetup = entityAuditSetup.get(modifyEvent.getPersister().getEntityName()); if (auditSetup == null || !auditSetup.isAuditModify()) return; auditedList = new ArrayList<Integer>(); names = modifyEvent.getPersister().getPropertyNames(); if (!auditSetup.isAuditModifyAllProperties()) { for (int i = 0; i < names.length; i++) if (auditSetup.isAuditModifyProperty(names[i])) auditedList.add(i); } else { for (int i = 0; i < names.length; i++) auditedList.add(i); } } finally { lock.unlock(); } if (auditedList.isEmpty()) return; String[] stateStr = new String[auditedList.size()]; String[] oldStateStr = new String[auditedList.size()]; String[] auditedNames = new String[auditedList.size()]; int j = 0; for (int i = 0; i < names.length; i++) { if (!auditedList.contains(i)) continue; Type type = modifyEvent.getPersister().getPropertyType(names[i]); if (type.isCollectionType()) continue; auditedNames[j] = names[i]; if (type.isEntityType()) { ClassMetadata metadata = modifyEvent.getPersister().getFactory() .getClassMetadata(type.getName()); stateStr[j] = entityPropertyToString(modifyEvent.getState()[i], metadata); oldStateStr[j] = entityPropertyToString(modifyEvent.getOldState()[i], metadata); } else { stateStr[j] = modifyEvent.getState()[i] == null ? null : modifyEvent.getState()[i].toString(); oldStateStr[j] = modifyEvent.getOldState()[i] == null ? null : modifyEvent.getOldState()[i].toString(); } j++; } // ?? ? if (j == 0) return; //?? ? ? if (names.length > j) { auditedNames = (String[]) ArrayUtils.subarray(auditedNames, 0, j); stateStr = (String[]) ArrayUtils.subarray(stateStr, 0, j); oldStateStr = (String[]) ArrayUtils.subarray(oldStateStr, 0, j); } sendAuditMessage(new EntityAuditEvent(modifyEvent.getPersister().getEntityName(), DatabaseAuditType.MODIFY, modifyEvent.getId().toString(), modifyEvent.getPersister().getIdentifierPropertyName(), auditedNames, stateStr, oldStateStr)); } catch (Exception e) { logger.error("audit modify failed", e); } }
From source file:gov.nih.nci.caarray.plugins.affymetrix.AffymetrixTsvFileReader.java
private void addColumnHeaders(String unparsedColumnHeaders, int headerNum, boolean dequoteColumnNames) { String[] columnNames = unparsedColumnHeaders.split(fieldSeparator); if (dequoteColumnNames) { for (int i = 0; i < columnNames.length; i++) { // erroneous PMD string buffer warning columnNames[i] = CaArrayUtils.dequoteString(columnNames[i]); // NOPMD }//from ww w .j a v a 2 s .c o m } List<String> headersList = Arrays .asList((String[]) ArrayUtils.subarray(columnNames, headerNum, columnNames.length)); checkHeaderDepth(headerNum, columnNames); columnHeaders.add(headerNum, headersList); }
From source file:com.gc.iotools.stream.is.ChunkInputStream.java
private boolean moveToNextStartMarker() throws IOException { boolean found; if (this.start.length == 0) { this.wrappedIs.mark(2); // if EOF stop. found = (this.wrappedIs.read() >= 0); this.wrappedIs.reset(); } else {//from w ww .jav a2 s . co m int n; found = false; final byte[] buffer = new byte[EasyStreamConstants.SKIP_BUFFER_SIZE + this.start.length]; do { this.wrappedIs.mark(EasyStreamConstants.SKIP_BUFFER_SIZE + this.start.length); n = StreamUtils.tryReadFully(this.wrappedIs, buffer, 0, EasyStreamConstants.SKIP_BUFFER_SIZE + this.start.length); if (n > 0) { final int pos = ArrayTools.indexOf(ArrayUtils.subarray(buffer, 0, n), this.start); if (pos >= 0) { // found found = true; this.wrappedIs.reset(); final int skip = pos + (this.showMarkers ? 0 : this.start.length); this.wrappedIs.skip(skip); } else { // not found if (n - this.start.length > 0) { this.wrappedIs.reset(); this.wrappedIs.skip(n - this.start.length); } } } } while (!found && (n >= 0)); } return found; }
From source file:com.intel.daal.spark.rdd.DistributedNumericTable.java
/** * Transforms a DistributedNumericTable into a JavaRDD<Vector>. * @param distNT - The source DistributedNumericTable. * @return A JavaRDD<Vector> object. * @throws IllegalArgumentException.//from ww w . ja va2s . c om */ public static JavaRDD<Vector> toJavaVectorRDD(DistributedNumericTable distNT) throws IllegalArgumentException { return distNT.numTables.flatMap(new FlatMapFunction<NumericTableWithIndex, Vector>() { public List<Vector> call(NumericTableWithIndex nt) { DaalContext context = new DaalContext(); NumericTable table = nt.getTable(context); double[] data = (table instanceof HomogenNumericTable) ? ((HomogenNumericTable) table).getDoubleArray() : null; if (data == null) { throw new IllegalArgumentException("Invalid NumericTable type"); } long begin = 0; long end = nt.numOfCols(); ArrayList<Vector> veclist = new ArrayList<Vector>(); while (begin < data.length) { double[] row = ArrayUtils.subarray(data, (int) begin, (int) end); DenseVector dv = new DenseVector(row); veclist.add(dv); begin = end; end += nt.numOfCols(); } context.dispose(); return veclist; } }); }
From source file:com.ephesoft.dcma.encryption.core.EncryptorDecryptor.java
/** * This method is used to decrypt the encrypted string. * @param encryptedString {@link String} * @return {@link String}/*from ww w .ja v a2s . c om*/ * @throws CryptographyException {@link CryptographyException} */ public String decryptString(String encryptedString) throws CryptographyException { byte[] data; try { data = encryptedString.getBytes("UTF8"); } catch (UnsupportedEncodingException e) { LOGGER.error("Could not decode string using UTF-8", e); throw new CryptographyException("Could not decode string using UTF-8", e); } data = Base64.decodeBase64(data); byte[] salt = ArrayUtils.subarray(data, 0, EncryptionConstants.SALT_LENGTH); data = ArrayUtils.subarray(data, EncryptionConstants.SALT_LENGTH, data.length); byte[] result = startCrypting(data, salt, false); return new String(result); }