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:ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifierFactory.java
private static SampleIdentifierOrPattern parse(String text, boolean isPattern) { String tokens[] = text.split(IDENTIFIER_SEPARARTOR_STRING); if (tokens.length == 0) { throw new UserFailureException(ILLEGAL_EMPTY_IDENTIFIER); }/*from ww w . j a va 2s. c o m*/ String sampleCode = tokens[tokens.length - 1]; String[] ownerTokens = (String[]) ArrayUtils.subarray(tokens, 0, tokens.length - 1); SampleOwnerIdentifier owner = parseSampleOwner(ownerTokens, text); validateSampleCode(sampleCode, isPattern); return new SampleIdentifierOrPattern(sampleCode, owner); }
From source file:com.amalto.core.load.context.BufferStateContextWriter.java
public void writeCharacters(XMLStreamReader reader) throws XMLStreamException { char[] characters = reader.getTextCharacters(); int textStart = reader.getTextStart(); char[] textCharacters = ArrayUtils.subarray(characters, textStart, textStart + reader.getTextLength()); processedElements.add(new ProcessedCharacters(textCharacters)); }
From source file:datacite.oai.provider.util.BOMUtil.java
/** * Remove a Byte Order Mark from the beginning of a byte[]. * @param array The byte[] to remove a BOM from. * @param BOM The byte[] BOM to remove. * @return The original byte[] without BOM. *///from w w w .j ava 2 s . c o m public static byte[] removeBOM(byte[] array, byte[] BOM) { int i; boolean hasBOM = true; for (i = 0; (i < BOM.length) && hasBOM; i++) { if ((byte) array[i] != (byte) BOM[i]) { hasBOM = false; } } if (hasBOM) { return ArrayUtils.subarray(array, BOM.length, array.length); } else { return array; } }
From source file:com.github.neoio.net.message.staging.file.TestFileMessageStaging.java
@Test public void test_tempWrite() { ByteBuffer buffer = ByteBuffer.allocate(1024); buffer.put("Hello World".getBytes()); buffer.flip();/*from ww w.jav a 2 s. com*/ staging.writeTempWriteBytes(buffer); Assert.assertTrue(staging.hasTempWriteBytes()); buffer.clear(); staging.readTempWriteBytes(buffer); Assert.assertEquals("Hello World", new String(ArrayUtils.subarray(buffer.array(), 0, "Hello World".getBytes().length))); staging.resetTempWriteBytes(); Assert.assertFalse(staging.hasTempWriteBytes()); }
From source file:com.jaromin.alfresco.extractor.AbstractBitmapExtractor.java
/** * Check if the next series of bytes from the stream matches the sequence. * The int 'b' is the most recently-read byte and the input stream is positioned * to read the byte immediately following 'b'. * If the match fails, the stream is reset. If it matches, the stream is NOT reset. * @param seq/*from w w w. j a va 2 s .co m*/ * @param in * @param b * @return * @throws IOException */ protected boolean matches(byte[] seq, InputStream in, int b) throws IOException { if (((byte) b) == seq[0]) { // potential match, read next 7 bytes byte[] buf = new byte[seq.length - 1]; in.mark(buf.length); if (in.read(buf) == -1) { in.reset(); return false; } else { if (ArrayUtils.isEquals(buf, ArrayUtils.subarray(seq, 1, seq.length))) { // last 7 bytes return true; } in.reset(); // rewind } } return false; }
From source file:it.drwolf.ridire.session.async.callable.CorpusDeleter.java
public IndexingResult call() { IndexingResult indexingResult = new IndexingResult(); Lifecycle.beginCall();//from www . java 2 s . com try { this.contextsIndexManager = (ContextsIndexManager) Component.getInstance("contextsIndexManager"); TopDocs termDocs = null; int updated = 0; int totToBeModified = 0; this.contextsIndexManager.reOpenIndexReaderW(); termDocs = this.contextsIndexManager.getIndexSearcherW() .search(new TermQuery(new Term("corpus", this.corpusName)), Integer.MAX_VALUE); totToBeModified = termDocs.totalHits; for (int i = 0; i < termDocs.totalHits; i += 30) { ScoreDoc[] tmp = (ScoreDoc[]) ArrayUtils.subarray(termDocs.scoreDocs, i, i + 30); for (ScoreDoc scoreDoc : tmp) { this.contextsIndexManager.reOpenIndexReaderW(); Document d = this.contextsIndexManager.getIndexSearcherW().doc(scoreDoc.doc); List<String> corporaNames = new ArrayList<String>(); for (String cn : d.getValues("corpus")) { if (!cn.equals(this.corpusName)) { corporaNames.add(cn); } } d.removeFields("corpus"); if (corporaNames.size() > 0) { for (String cn : corporaNames) { d.add(new Field("corpus", cn, Field.Store.YES, Field.Index.NOT_ANALYZED)); } } try { this.contextsIndexManager.closeIndexWriter(); this.contextsIndexManager.getIndexSearcherW().getIndexReader().deleteDocument(scoreDoc.doc); this.contextsIndexManager.getIndexSearcherW().getIndexReader().close(); this.contextsIndexManager.openIndexWriterWithoutCreating(); this.contextsIndexManager.getIndexWriter().updateDocument(new Term("corpus"), d); this.contextsIndexManager.closeIndexWriter(); } catch (RuntimeException e) { e.printStackTrace(); throw e; } ++updated; this.percentage = updated / (totToBeModified * 1.0f); } } this.contextsIndexManager.openIndexWriterWithoutCreating(); this.contextsIndexManager.getIndexWriter().expungeDeletes(); this.contextsIndexManager.closeIndexWriter(); } catch (Exception e) { e.printStackTrace(); } Lifecycle.endCall(); this.setTerminated(true); return indexingResult; }
From source file:com.asual.lesscss.ResourcePackage.java
public static ResourcePackage fromString(String source) { if (!StringUtils.isEmpty(source)) { try {/* w w w. j ava2 s. co m*/ String key; String path = null; String extension = null; int slashIndex = source.lastIndexOf("/"); int dotIndex = source.lastIndexOf("."); if (dotIndex != -1 && slashIndex < dotIndex) { extension = source.substring(dotIndex + 1); path = source.substring(0, dotIndex); } else { path = source; } if (extension != null && !extensions.contains(extension)) { return null; } String[] parts = path.replaceFirst("^/", "").split(SEPARATOR); if (cache.containsValue(source)) { key = getKeyFromValue(cache, source); } else { key = parts[parts.length - 1]; byte[] bytes = null; try { bytes = Base64.decodeBase64(key.getBytes(ENCODING)); bytes = inflate(bytes); } catch (Exception e) { } key = new String(bytes, ENCODING); } String[] data = key.split(NEW_LINE); ResourcePackage rp = new ResourcePackage((String[]) ArrayUtils.subarray(data, 1, data.length)); int mask = Integer.valueOf(data[0]); if ((mask & NAME_FLAG) != 0) { rp.setName(parts[0]); } if ((mask & VERSION_FLAG) != 0) { rp.setVersion(parts[rp.getName() != null ? 1 : 0]); } rp.setExtension(extension); return rp; } catch (Exception e) { } } return null; }
From source file:com.github.tojo.session.cookies.SignatureStrategyDefaultImplTest.java
@Test public void testSignAndPrefixSessionData() throws Exception { byte[] signedsampleSessionDataLoremIpsumAsBytes = sut.sign(sampleSessionDataLoremIpsumAsBytes); byte[] signedSessionData = sut.sign(sampleSessionDataLoremIpsumAsBytes); sut.validate(signedsampleSessionDataLoremIpsumAsBytes); sut.validate(signedSessionData);/*from ww w . j a va 2 s . com*/ // extract the session data and check it byte[] sessionData = ArrayUtils.subarray(signedSessionData, SIGNATURE_LENGTH, signedSessionData.length); assertTrue(Arrays.equals(sampleSessionDataLoremIpsumAsBytes, sessionData)); }
From source file:com.haulmont.cuba.gui.FrameContextImpl.java
@Override public <T> T getValue(String property) { final String[] elements = ValuePathHelper.parse(property); String[] path = elements;/*from ww w . ja va 2 s .co m*/ Component component = frame.getComponent(property); while (component == null && path.length > 1) { // in case of property contains a drill-down part path = (String[]) ArrayUtils.subarray(path, 0, path.length - 1); component = frame.getComponent(ValuePathHelper.format(path)); } if (component == null || component instanceof Frame || ((component instanceof Component.Wrapper) && ((Component.Wrapper) component).getComponent() instanceof Frame)) { // if component not found or found a frame, try to search in the parent frame if (frame.getFrame() != null && frame.getFrame() != frame) return frame.getFrame().getContext().getValue(property); else return null; } final Object value = getValue(component); if (value == null) return null; if (path.length == elements.length) { //noinspection unchecked return (T) value; } else { final java.util.List<String> propertyPath = Arrays.asList(elements).subList(path.length, elements.length); final String[] properties = propertyPath.toArray(new String[propertyPath.size()]); if (value instanceof Instance) { //noinspection RedundantTypeArguments return InstanceUtils.<T>getValueEx(((Instance) value), properties); } else if (value instanceof EnumClass) { if (properties.length == 1 && "id".equals(properties[0])) { //noinspection unchecked return (T) ((EnumClass) value).getId(); } else { throw new UnsupportedOperationException( String.format("Can't get property '%s' of enum %s", propertyPath, value)); } } else { return null; } } }
From source file:com.yahoo.egads.utilities.SpectralMethods.java
public static RealMatrix createHankelMatrix(RealMatrix data, int windowSize) { int n = data.getRowDimension(); int m = data.getColumnDimension(); int k = n - windowSize + 1; RealMatrix res = MatrixUtils.createRealMatrix(k, m * windowSize); double[] buffer = {}; for (int i = 0; i < n; ++i) { double[] row = data.getRow(i); buffer = ArrayUtils.addAll(buffer, row); if (i >= windowSize - 1) { RealMatrix mat = MatrixUtils.createRowRealMatrix(buffer); res.setRowMatrix(i - windowSize + 1, mat); buffer = ArrayUtils.subarray(buffer, m, buffer.length); }/*from www. j av a2 s .c o m*/ } return res; }