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:net.mikaboshi.intra_mart.tools.log_stats.parser.ExceptionLogParserV7.java
public ExceptionLog parse(String string) { if (string == null) { return null; }/*from ww w . j a va 2s . c o m*/ String[] lines = LogStringUtil.lines(string); if (lines.length < 9) { warn("invalid exception log"); this.parameter.getErrorCounter().increment(); return null; } ExceptionLog log = new ExceptionLog(); log.groupingType = this.parameter.getExceptionGroupingType(); try { log.date = dateFormat.parse(getValue(lines[0])); } catch (ParseException e) { warn("invalid date : " + lines[0]); this.parameter.getErrorCounter().increment(); return null; } if (!isInRange(log)) { return null; } log.level = Level.toEnum(getValue(lines[1])); log.logger = getValue(lines[2]); log.logId = getValue(lines[3]); log.thread = getValue(lines[4]); log.logThreadGroup = getValue(lines[5]); log.message = getValue(lines[6]); for (int i = 7; i < lines.length; i++) { if (lines[i].length() == 0 && i < lines.length - 1 && STACKTRACE_BIGIN_PATTERN.matcher(lines[i + 1]).find()) { // ??????? => ??? log.stackTrace = StringUtils.join(ArrayUtils.subarray(lines, i + 1, lines.length - 1), IOUtils.LINE_SEPARATOR); break; } else { // ??? log.message += IOUtils.LINE_SEPARATOR + lines[i]; } } return log; }
From source file:com.github.tojo.session.cookies.SessionInACookieDefaultImpl.java
@Override public byte[] decode(CookieValue cookieValue) throws TimeoutException, SignatureException, BlacklistException { // 1. check blacklist blacklistStrategy.check(cookieValue); // 2. advance session timeout timeoutStrategy.advance(cookieValue); // 3. decode//w w w . ja v a 2 s . c om byte[] dataWithSessionId; dataWithSessionId = decodeDecryptAndVerifySignature(cookieValue.asBytes()); // 4. extract the session id byte[] sessionId = ArrayUtils.subarray(dataWithSessionId, 0, SESSION_ID_LENGTH); // 5. extract the session data byte[] sessionData = ArrayUtils.subarray(dataWithSessionId, SESSION_ID_LENGTH, dataWithSessionId.length); // 3. return the session data return sessionData; }
From source file:com.codenjoy.dojo.tetris.model.GameSetupRule.java
private List<Figure> initQueueWithFigures(FigureProperties[] figures, FigureQueue figureQueue) { List<Figure> result = new ArrayList<Figure>(); for (FigureProperties figure : figures) { Figure figureMock = mock(Figure.class); when(figureMock.getLeft()).thenReturn(figure.left()); when(figureMock.getRight()).thenReturn(figure.right()); when(figureMock.getTop()).thenReturn(figure.top()); when(figureMock.getBottom()).thenReturn(figure.bottom()); when(figureMock.getType()).thenReturn(figure.type()); result.add(figureMock);/*from w w w. j a v a2s . c om*/ } Figure[] values = result.toArray(new Figure[result.size()]); when(figureQueue.next()).thenReturn(values.length > 0 ? values[0] : null, values.length > 1 ? (Figure[]) ArrayUtils.subarray(values, 1, values.length) : null); return result; }
From source file:com.gs.obevo.dist.Main.java
private void execute(String[] args) { Pair<String, Procedure<String[]>> commandEntry = getDeployCommand(args); FileAppender logAppender = getLogAppender(commandEntry.getOne()); StopWatch changeStopWatch = new StopWatch(); changeStopWatch.start();/*w w w .ja v a 2 s. c o m*/ LOG.info("Starting action at time [" + new Date() + "]"); boolean success = false; try { String[] argSubset = (String[]) ArrayUtils.subarray(args, 1, args.length); commandEntry.getTwo().value(argSubset); success = true; } finally { changeStopWatch.stop(); long runtimeSeconds = changeStopWatch.getTime() / 1000; String successString = success ? "successfully" : "with errors"; LOG.info("Action completed " + successString + " at " + new Date() + ", " + "took " + runtimeSeconds + " seconds. If you need more information, " + "you can see the log at: " + logAppender.getFile()); LogUtil.closeAppender(logAppender); } }
From source file:de.codesourcery.jasm16.compiler.io.FileObjectCodeWriterTest.java
public void testSkipToOffset3500BeforeWrite() throws Exception { final byte[] input = "test".getBytes(); final int offset = 3500; writer.advanceToWriteOffset(Address.byteAddress(offset)); writer.writeObjectCode(input);/*from w ww . jav a2 s .c o m*/ assertEquals(Address.byteAddress(offset + input.length), writer.getCurrentWriteOffset()); writer.close(); final byte[] data = writer.getBytes(); // System.out.println( Misc.toHexDumpWithAddresses( offset , data , 8 ) ); assertEquals(offset + input.length, data.length); byte[] zeros = new byte[offset]; assertTrue(ArrayUtils.isEquals(zeros, ArrayUtils.subarray(data, 0, offset))); assertTrue(ArrayUtils.isEquals(input, ArrayUtils.subarray(data, offset, data.length))); }
From source file:eu.europa.esig.dss.xades.validation.XMLDocumentValidator.java
private boolean isXmlPreamble(byte[] preamble) { byte[] startOfPramble = ArrayUtils.subarray(preamble, 0, xmlPreamble.length); return Arrays.equals(startOfPramble, xmlPreamble) || Arrays.equals(startOfPramble, xmlUtf8); }
From source file:com.opengamma.integration.copier.portfolio.reader.ZippedPortfolioReader.java
private PortfolioReader getReader(ZipEntry entry) { if (!entry.isDirectory() && entry.getName().substring(entry.getName().lastIndexOf('.')).equalsIgnoreCase(SHEET_EXTENSION)) { try {/*from ww w . jav a 2 s . c o m*/ // Extract full path String[] fullPath = entry.getName().split("/"); // Extract security name String secType = fullPath[fullPath.length - 1].substring(0, fullPath[fullPath.length - 1].lastIndexOf('.')); _currentPath = (String[]) ArrayUtils.subarray(fullPath, 0, fullPath.length - 1); // Set up a sheet reader and a row parser for the current CSV file in the ZIP archive SheetReader sheet = new CsvSheetReader(_zipFile.getInputStream(entry)); RowParser parser = JodaBeanRowParser.newJodaBeanRowParser(secType); if (parser == null) { s_logger.error("Could not build a row parser for security type '" + secType + "'"); return null; } if (!_ignoreVersion) { if (_versionMap.get(secType) == null) { s_logger.error("Versioning hash for security type '" + secType + "' could not be found"); return null; } if (parser.getSecurityHashCode() != _versionMap.get(secType)) { s_logger.error("The parser version for the '" + secType + "' security (hash " + Integer.toHexString(parser.getSecurityHashCode()) + ") does not match the data stored in the archive (hash " + Integer.toHexString(_versionMap.get(secType)) + ")"); return null; } } s_logger.info("Processing rows in archive entry " + entry.getName() + " as " + secType); // Create a simple portfolio reader for the current sheet return new SingleSheetSimplePortfolioReader(sheet, parser); } catch (Throwable ex) { s_logger.warn( "Could not import from " + entry.getName() + ", skipping file (exception is " + ex + ")"); return null; } } else { return null; } }
From source file:gda.device.detector.countertimer.TfgScalerWithDarkCurrent.java
private DarkCurrentResults collectDarkCurrent(final DarkCurrentBean bean) throws Exception { final Scannable shutter = (Scannable) Finder.getInstance().find(bean.getShutterName()); String originalShutterPosition = shutter.getPosition().toString(); if (!originalShutterPosition.equalsIgnoreCase("Close")) { shutter.moveTo("Close"); }// w w w . j a v a 2 s . c o m setCollectionTime(bean.getDarkCollectionTime()); // do not change the collection time - simply re-use the current time which the collectData(); Thread.sleep(Math.round(bean.getDarkCollectionTime()) * 1000); // Throws interrupted exception if the thread // executing this method. while (isBusy()) { // TODO timeout of 2*bean.getDarkCollectionTime() Thread.sleep(100); } double[] countsDbl = super.readout(); if (timeChannelRequired) { countsDbl = ArrayUtils.subarray(countsDbl, 1, countsDbl.length); } Double[] counts = ArrayUtils.toObject(countsDbl); if (useReset) { shutter.moveTo("Reset"); } shutter.moveTo("Open"); setCollectionTime(bean.getOriginalCollectionTime()); return new DarkCurrentResults(bean.getDarkCollectionTime(), counts); }
From source file:com.ebay.cloud.cms.query.executor.SearchActionHelper.java
public static void initSortOn(SearchOption searchOption, ParseQueryNode parseNode, QueryContext queryContext, SearchQuery searchQuery, ISearchStrategy queryStrategy) { if (queryContext.hasSortOn()) { List<String> sortOnList = queryContext.getSortOn(); // append default sortOn _oid if (!sortOnList.contains(InternalFieldEnum.ID.getName()) && queryContext.getPaginationMode() == PaginationMode.ID_BASED) { sortOnList.add(InternalFieldEnum.ID.getName()); }/*from w w w . jav a 2s . c o m*/ List<Integer> sortOrderList = new ArrayList<Integer>(sortOnList.size()); List<ISearchField> sortOnFieldList = new ArrayList<ISearchField>(sortOnList.size()); MetaClass metaClass = parseNode.getMetaClass(); Map<String, GroupField> grpFields = null; if (parseNode.getGroup() != null) { grpFields = parseNode.getGroup().getGrpFields(); } for (String sortFieldName : sortOnList) { String[] fields = sortFieldName.split("\\."); MetaField sortMetaField = metaClass.getFieldByName(fields[0]); validateSortField(sortMetaField, sortFieldName, fields, metaClass); // if (sortMetaField == null) { // throw new QueryExecuteException(QueryErrCodeEnum.METAFIELD_NOT_FOUND, "Can't find sort field " + sortFieldName + " on " + metaClass.getName()); // } // // array sort not supported // if (sortMetaField.getCardinality() == CardinalityEnum.Many && fields.length == 1) { // throw new QueryExecuteException(QueryErrCodeEnum.ARRAY_SORT_NOT_SUPPORT, "Can't sort on array field " + sortFieldName + " on " + metaClass.getName()); // } // if (sortMetaField.getDataType() == DataTypeEnum.JSON) { // throw new QueryExecuteException(QueryErrCodeEnum.JSON_SORT_NOT_SUPPORT, "Can't sort on json field " + sortFieldName + " on " + metaClass.getName()); // } String innerField = fields.length > 1 ? StringUtils.join(ArrayUtils.subarray(fields, 1, fields.length), '.') : null; ISearchField sortOnField = null; if (grpFields != null) { sortOnField = grpFields.get(fields[0]); } if (sortOnField == null) { sortOnField = new SelectionField(sortMetaField, innerField, queryStrategy); } sortOnFieldList.add(sortOnField); // sortOn must be in projection for ID based pagination ProjectionField projField = new ProjectionField(sortMetaField, innerField, false, queryStrategy); if (!searchQuery.getSearchProjection().getFields().contains(projField)) { searchQuery.getSearchProjection().getFields().add(projField); } } setOrder(queryContext, sortOrderList, sortOnFieldList); // if (queryContext.hasSortOrder()) { // List<SortOrder> soList = queryContext.getSortOrder(); // for (SortOrder order : soList) { // if (order == SortOrder.asc) { // sortOrderList.add(SearchOption.ASC_ORDER); // } else { // sortOrderList.add(SearchOption.DESC_ORDER); // } // } // } else { // // set default sort order as ascend // for (int i = 0; i < sortOnFieldList.size(); i++) { // sortOrderList.add(SearchOption.ASC_ORDER); // } // } searchOption.setSortField(sortOnFieldList, sortOrderList, metaClass); } else { // sort on _oid if not given searchOption.setSort(Arrays.asList(InternalFieldEnum.ID.getName()), Arrays.asList(SearchOption.ASC_ORDER), parseNode.getMetaClass()); } }
From source file:edu.jhu.pha.vospace.node.NodePath.java
public String[] getNodeOuterPathArray() { if (enableAppContainer) return (String[]) ArrayUtils.subarray(pathTokens, 1, pathTokens.length); else//from w w w . j av a2s .c o m return pathTokens; }