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.apporiented.hermesftp.server.impl.ServerRFC959Test.java
/** * Test case: Block transfer, record structures. *///from w w w . jav a 2s. co m @Test public void testBlockTransfer() { try { byte[] data = createBlockData(); String str = getClient().sendAndReceive("MODE B"); assertTrue(str.startsWith("200")); str = getClient().sendAndReceive("STRU R"); assertTrue(str.startsWith("200")); str = getClient().sendAndReceive("TYPE E"); assertTrue(str.startsWith("200")); str = getClient().storeRaw(testFile, data); assertTrue(str.startsWith("226")); getClient().sendAndReceive("MODE S"); getClient().sendAndReceive("STRU F"); getClient().retrieveText(testFile); str = getClient().getTextData(); String br = System.getProperty("line.separator"); assertTrue(str.startsWith("ABBB" + br + "CCCCCCCC")); getClient().sendAndReceive("MODE S"); getClient().sendAndReceive("STRU R"); getClient().retrieveRaw(testFile); byte[] raw = getClient().getRawData(); assertTrue(ArrayUtils.contains(raw, (byte) 0xFF)); getClient().sendAndReceive("MODE B"); getClient().sendAndReceive("STRU R"); getClient().sendAndReceive("TYPE E"); getClient().retrieveRaw(testFile); raw = getClient().getRawData(); assertTrue(Arrays.equals(ArrayUtils.subarray(raw, 0, 11), new byte[] { -128, 0, 4, (byte) 0xC1, (byte) 0xC2, (byte) 0xC2, (byte) 0xC2, -64, 1, 2, (byte) 0xC3 })); getClient().sendAndReceive("DELE " + testFile); } catch (IOException e) { log.error(e); } }
From source file:edu.utdallas.bigsecret.crypter.CrypterMode3.java
/** * {@inheritDoc}//from w w w . j a v a 2 s . c o m */ public long unwrapTimestamp(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 Bytes.toLong(ArrayUtils.subarray(completeData, 12 + rowSize + famSize + quaSize, 12 + rowSize + famSize + quaSize + 8)); }
From source file:gov.nih.nci.caarray.plugins.affymetrix.AffymetrixTsvFileReader.java
private Record parseDataLine() { if (StringUtils.isEmpty(currentLine)) { return null; }//from w w w .java 2 s . co m String[] values = currentLine.split(fieldSeparator); int recordLevel = getRecordLevel(values); int previousLevel = currentRecord != null ? currentRecord.getRecordLevel() : 0; checkRecordLevel(currentLine, recordLevel, previousLevel); // PMD erroneously reports a UseStringBufferForStringAppends error here values = (String[]) ArrayUtils.subarray(values, recordLevel, values.length); // NOPMD Record record = new Record(recordLevel); List<String> headers = columnHeaders.get(recordLevel); for (int i = 0; i < headers.size(); i++) { String header = headers.get(i); addDataToRecord(i < values.length ? values[i] : "", record, header); } currentRecord = record; recordCount++; return record; }
From source file:com.palantir.atlasdb.ptobject.EncodingUtils.java
public static byte[] get32Bytes(byte[] b1, int offset) { return ArrayUtils.subarray(b1, offset, offset + 32); }
From source file:com.palantir.atlasdb.ptobject.EncodingUtils.java
public static long decodeLittleEndian(byte[] value, int offset) { byte[] subArray = ArrayUtils.subarray(value, offset, offset + PtBytes.SIZEOF_LONG); ArrayUtils.reverse(subArray);/*from w ww.j a v a 2 s. c o m*/ return PtBytes.toLong(subArray); }
From source file:com.adobe.acs.commons.images.impl.NamedTransformImageServlet.java
/** * Gets the NamedImageTransformers based on the Suffix segments in order. * * @param request the SlingHttpServletRequest object * @return a list of the NamedImageTransformers specified by the HTTP Request suffix segments *///from www.j a va 2 s. com protected final List<NamedImageTransformer> getNamedImageTransformers(final SlingHttpServletRequest request) { final List<NamedImageTransformer> transformers = new ArrayList<NamedImageTransformer>(); String[] suffixes = PathInfoUtil.getSuffixSegments(request); if (suffixes.length < 2) { log.warn("Named Transform Image Servlet requires at least one named transform"); return transformers; } int endIndex = suffixes.length - 1; // Its OK to check; the above check ensures there are 2+ segments if (StringUtils.isNumeric(PathInfoUtil.getSuffixSegment(request, suffixes.length - 2))) { endIndex--; } suffixes = (String[]) ArrayUtils.subarray(suffixes, 0, endIndex); for (final String transformerName : suffixes) { final NamedImageTransformer transformer = this.namedImageTransformers.get(transformerName); if (transformer != null) { transformers.add(transformer); } } return transformers; }
From source file:com.preferanser.shared.domain.EditorTest.java
@Test public void testValidate_WrongHandCards2() throws Exception { try {//from ww w .j a va 2 s . c om new Editor().setName(name).setDescription(description).setFourPlayers().setFirstTurn(SOUTH) .setWidow(widow).putCards(SOUTH, (Card[]) ArrayUtils.subarray(southCards, 0, 9)) .putCards(EAST, eastCards).putCards(WEST, westCards) .setHandContract(SOUTH, Contract.SIX_DIAMOND).setHandContract(EAST, Contract.PASS) .setHandContract(WEST, Contract.WHIST).build(); fail("WrongNumCardsPerHandValidationError expected"); } catch (EditorException e) { List<? extends EditorValidationError> expectedErrors = newArrayList( new WrongNumCardsPerHandValidationError(ImmutableMap.of(SOUTH, 9))); assertReflectionEquals(expectedErrors, e.getBuilderErrors()); } }
From source file:ips1ap101.lib.core.jsf.JSF.java
public static CampoArchivoMultiPart upload(Part part, String carpeta, EnumOpcionUpload opcion) throws Exception { Bitacora.trace(JSF.class, "upload", part, carpeta, opcion); if (part == null) { return null; }// w w w . j a va2 s . co m if (part.getSize() == 0) { return null; } String originalName = getPartFileName(part); if (StringUtils.isBlank(originalName)) { return null; } CampoArchivoMultiPart campoArchivo = new CampoArchivoMultiPart(); campoArchivo.setPart(part); campoArchivo.setClientFileName(null); campoArchivo.setServerFileName(null); /**/ Bitacora.trace(JSF.class, "upload", "name=" + part.getName()); Bitacora.trace(JSF.class, "upload", "type=" + part.getContentType()); Bitacora.trace(JSF.class, "upload", "size=" + part.getSize()); /**/ String sep = System.getProperties().getProperty("file.separator"); String validChars = StrUtils.VALID_CHARS; String filepath = null; if (STP.esIdentificadorArchivoValido(carpeta)) { filepath = carpeta.replace(".", sep); } long id = LongUtils.getNewId(); // String filename = STP.getRandomString(); String filename = id + ""; String pathname = Utils.getAttachedFilesDir(filepath) + filename; String ext = Utils.getExtensionArchivo(originalName); if (StringUtils.isNotBlank(ext)) { String str = ext.toLowerCase(); if (StringUtils.containsOnly(str, validChars)) { filename += "." + str; pathname += "." + str; } } /**/ // part.write(pathname); /**/ // OutputStream outputStream = new FileOutputStream(pathname); // outputStream.write(IOUtils.readFully(part.getInputStream(), -1, false)); /**/ int bytesRead; int bufferSize = 8192; byte[] bytes = null; byte[] buffer = new byte[bufferSize]; try (InputStream input = part.getInputStream(); OutputStream output = new FileOutputStream(pathname)) { while ((bytesRead = input.read(buffer)) != -1) { if (!EnumOpcionUpload.FILA.equals(opcion)) { output.write(buffer, 0, bytesRead); } if (!EnumOpcionUpload.ARCHIVO.equals(opcion)) { if (bytesRead < bufferSize) { bytes = ArrayUtils.addAll(bytes, ArrayUtils.subarray(buffer, 0, bytesRead)); } else { bytes = ArrayUtils.addAll(bytes, buffer); } } } } /**/ String clientFilePath = null; String clientFileName = clientFilePath == null ? originalName : clientFilePath + originalName; String serverFileName = Utils.getWebServerRelativePath(pathname); if (!EnumOpcionUpload.ARCHIVO.equals(opcion)) { String contentType = part.getContentType(); long size = part.getSize(); insert(id, clientFileName, serverFileName, contentType, size, bytes); } campoArchivo.setClientFileName(clientFileName); campoArchivo.setServerFileName(serverFileName); return campoArchivo; }
From source file:edu.utdallas.bigsecret.crypter.CrypterMode1.java
/** * {@inheritDoc}// www . j a v a 2 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"); int qualifierIndexSize = getIndexQualifierDataSize(); byte[] completeData = m_keyCipher.decrypt(qualifier, qualifierIndexSize); 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:com.mnxfst.testing.handler.exec.PTestPlanExecutionContext.java
/** * Extracts the {@link Method method representations} for the given path of getter methods * @param varType/*from www .java2 s . com*/ * @param getterMethodNames * @param result * @throws ContextVariableEvaluationFailedException */ protected void extractGetterMethods(Class<?> varType, String[] getterMethodNames, List<Method> result) throws ContextVariableEvaluationFailedException { if (varType != null && getterMethodNames != null && getterMethodNames.length > 0) { String nextGetter = getterMethodNames[0]; try { Method getterMethod = varType.getMethod(nextGetter); result.add(getterMethod); extractGetterMethods(getterMethod.getReturnType(), (String[]) ArrayUtils.subarray(getterMethodNames, 1, getterMethodNames.length), result); } catch (NoSuchMethodException e) { throw new ContextVariableEvaluationFailedException( "No such getter '" + nextGetter + "' for class " + varType.getName()); } } }