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:org.eclipse.smarthome.core.voice.internal.VoiceConsoleCommandExtension.java
@Override public void execute(String[] args, Console console) { if (args.length > 0) { String subCommand = args[0]; switch (subCommand) { case SUBCMD_SAY: if (args.length > 1) { say((String[]) ArrayUtils.subarray(args, 1, args.length), console); } else { console.println("Specify text to say (e.g. 'say hello')"); }//from w w w . j ava2 s . c o m return; case SUBCMD_INTERPRET: if (args.length > 1) { interpret((String[]) ArrayUtils.subarray(args, 1, args.length), console); } else { console.println("Specify text to interpret (e.g. 'interpret turn all lights off')"); } return; case SUBCMD_VOICES: for (Voice voice : voiceManager.getAllVoices()) { console.println( voice.getUID() + " " + voice.getLabel() + " - " + voice.getLocale().getDisplayName()); } return; default: break; } } else { printUsage(console); } }
From source file:org.ejbca.core.protocol.ocsp.ProtocolOcspHttpTest.java
/** * Read the payload of a HTTP response as a byte array. */// ww w . j a va2 s.c o m private byte[] getHttpResponse(InputStream ins) throws IOException { byte buf[] = inputStreamToBytes(ins); int i = 0; // Removing the HTTP headers. The HTTP headers end at the last // occurrence of "\r\n". for (i = buf.length - 1; i > 0; i--) { if ((buf[i] == 0x0A) && (buf[i - 1] == 0x0D)) { break; } } byte[] header = ArrayUtils.subarray(buf, 0, i + 1); log.debug("HTTP reponse header: " + new String(header)); log.debug("HTTP reponse header size: " + header.length); log.debug("Stream length: " + buf.length); log.debug("HTTP payload length: " + (buf.length - header.length)); return ArrayUtils.subarray(buf, header.length, buf.length); }
From source file:org.flinkspector.core.runtime.MessageType.java
/** * Gets the payload of message./*from w w w . j av a2 s . co m*/ * * @param message byte array representing the message. * @return byte array containing the payload. */ public byte[] getPayload(byte[] message) throws UnsupportedEncodingException { if (this == OPEN) { return getOpenPayload(message); } return ArrayUtils.subarray(message, length, message.length); }
From source file:org.flinkspector.core.runtime.MessageType.java
/** * Extracts the serializer from an open message. * * @param message byte array representing the message. * @return serialized serializer.//from ww w . ja va2 s . com * @throws UnsupportedEncodingException */ private byte[] getOpenPayload(byte[] message) throws UnsupportedEncodingException { int length = new String(message, "UTF-8").indexOf(";") + 1; return ArrayUtils.subarray(message, length, message.length); }
From source file:org.geoserver.restupload.ResumableUploadTest.java
@Test public void testPartialUpload() throws Exception { String uploadId = sendPostRequest(); MockHttpServletRequest request = createRequest("/rest/resumableupload/" + uploadId); request.setMethod("PUT"); request.setContentType("application/octet-stream"); byte[] bigFile = generateFileAsBytes(); byte[] partialFile = ArrayUtils.subarray(bigFile, 0, (int) partialSize); request.setContent(partialFile);// www. jav a 2 s . c o m request.addHeader("Content-type", "application/octet-stream"); request.addHeader("Content-Length", String.valueOf(bigFile.length)); MockHttpServletResponse response = dispatch(request); assertEquals(ResumableUploadCatalogResource.RESUME_INCOMPLETE.getCode(), response.getStatus()); assertEquals(null, response.getHeader("Content-Length")); assertEquals("0-" + (partialSize - 1), response.getHeader("Range")); File uploadedFile = getTempPath(uploadId); assertTrue(uploadedFile.exists()); assertEquals(partialSize, uploadedFile.length()); boolean checkBytes = Arrays.equals(partialFile, toBytes(new FileInputStream(uploadedFile))); assertTrue(checkBytes); }
From source file:org.geoserver.restupload.ResumableUploadTest.java
@Test public void testUploadPartialResume() throws Exception { String uploadId = sendPostRequest(); byte[] bigFile = generateFileAsBytes(); byte[] partialFile1 = ArrayUtils.subarray(bigFile, 0, (int) partialSize); // First upload MockHttpServletRequest request = createRequest("/rest/resumableupload/" + uploadId); request.setMethod("PUT"); request.setContentType("application/octet-stream"); request.setContent(partialFile1);/* w w w . ja va 2 s .com*/ request.addHeader("Content-type", "application/octet-stream"); request.addHeader("Content-Length", String.valueOf(bigFile.length)); dispatch(request); // Resume upload request = createRequest("/rest/resumableupload/" + uploadId); request.setMethod("PUT"); request.setContentType("application/octet-stream"); byte[] partialFile2 = ArrayUtils.subarray(bigFile, (int) partialSize, (int) partialSize * 2); request.setContent(partialFile2); request.addHeader("Content-type", "application/octet-stream"); request.addHeader("Content-Length", String.valueOf(partialFile2.length)); request.addHeader("Content-Range", "bytes " + partialSize + "-" + partialSize * 2 + "/" + bigFile.length); MockHttpServletResponse response = dispatch(request); assertEquals(ResumableUploadCatalogResource.RESUME_INCOMPLETE.getCode(), response.getStatus()); assertEquals(null, response.getHeader("Content-Length")); assertEquals("0-" + (partialSize * 2 - 1), response.getHeader("Range")); File uploadedFile = getTempPath(uploadId); assertTrue(uploadedFile.exists()); assertEquals(partialSize * 2, uploadedFile.length()); // Check uploaded file byte by byte boolean checkBytes = Arrays.equals(ArrayUtils.addAll(partialFile1, partialFile2), toBytes(new FileInputStream(uploadedFile))); assertTrue(checkBytes); }
From source file:org.geoserver.restupload.ResumableUploadTest.java
@Test public void testUploadFullResume() throws Exception { String uploadId = sendPostRequest(); byte[] bigFile = generateFileAsBytes(); byte[] partialFile1 = ArrayUtils.subarray(bigFile, 0, (int) partialSize); // First upload MockHttpServletRequest request = createRequest("/rest/resumableupload/" + uploadId); request.setMethod("PUT"); request.setContentType("application/octet-stream"); request.setContent(partialFile1);//from ww w .jav a 2 s.co m request.addHeader("Content-type", "application/octet-stream"); request.addHeader("Content-Length", String.valueOf(bigFile.length)); dispatch(request); // Resume upload request = createRequest("/rest/resumableupload/" + uploadId); request.setMethod("PUT"); request.setContentType("application/octet-stream"); byte[] partialFile2 = ArrayUtils.subarray(bigFile, (int) partialSize, bigFile.length); request.setContent(partialFile2); request.addHeader("Content-type", "application/octet-stream"); request.addHeader("Content-Length", String.valueOf(partialFile2.length)); request.addHeader("Content-Range", "bytes " + partialSize + "-" + bigFile.length + "/" + bigFile.length); MockHttpServletResponse response = dispatch(request); assertEquals(Status.SUCCESS_OK.getCode(), response.getStatus()); File uploadedFile = getTempPath(uploadId); assertFalse(uploadedFile.exists()); File destinationFile = new File(FilenameUtils.concat(root, fileName.replaceAll("^/", ""))); assertTrue(destinationFile.exists()); assertEquals(bigFile.length, destinationFile.length()); // Check uploaded file byte by byte boolean checkBytes = Arrays.equals(bigFile, toBytes(new FileInputStream(destinationFile))); assertTrue(checkBytes); // Check response content String restUrl = response.getContentAsString(); assertEquals(fileName.replaceAll("^/", ""), restUrl); }
From source file:org.geoserver.restupload.ResumableUploadTest.java
@Test public void testPartialCleanup() throws Exception { // Change cleanup expirationDelay ResumableUploadResourceCleaner cleaner = (ResumableUploadResourceCleaner) applicationContext .getBean("resumableUploadStorageCleaner"); cleaner.setExpirationDelay(1000);//from www . j a va 2 s .c o m // Upload file String uploadId = sendPostRequest(); byte[] bigFile = generateFileAsBytes(); byte[] partialFile = ArrayUtils.subarray(bigFile, 0, (int) partialSize); MockHttpServletRequest request = createRequest("/rest/resumableupload/" + uploadId); request.setMethod("PUT"); request.setContentType("application/octet-stream"); request.setContent(partialFile); request.addHeader("Content-type", "application/octet-stream"); request.addHeader("Content-Length", String.valueOf(bigFile.length)); dispatch(request); File uploadedFile = getTempPath(uploadId); assertTrue(uploadedFile.exists()); // Wait to cleanup, max 2 minutes long startTime = new Date().getTime(); while (uploadedFile.exists() && (new Date().getTime() - startTime) < 120000) { Thread.sleep(1000); } assertTrue(!uploadedFile.exists()); cleaner.setExpirationDelay(300000); }
From source file:org.geoserver.restupload.ResumableUploadTest.java
@Test public void testGetAfterPartial() throws Exception { String uploadId = sendPostRequest(); byte[] bigFile = generateFileAsBytes(); byte[] partialFile = ArrayUtils.subarray(bigFile, 0, (int) partialSize); // First upload MockHttpServletRequest request = createRequest("/rest/resumableupload/" + uploadId); request.setMethod("PUT"); request.setContentType("application/octet-stream"); request.setContent(partialFile);//from ww w . j a va 2 s. c o m request.addHeader("Content-type", "application/octet-stream"); request.addHeader("Content-Length", String.valueOf(bigFile.length)); dispatch(request); File uploadedFile = getTempPath(uploadId); assertTrue(uploadedFile.exists()); MockHttpServletResponse response = getAsServletResponse("/rest/resumableupload/" + uploadId, "text/plain"); assertEquals(ResumableUploadCatalogResource.RESUME_INCOMPLETE.getCode(), response.getStatus()); assertEquals(null, response.getHeader("Content-Length")); assertEquals("0-" + (partialSize - 1), response.getHeader("Range")); }
From source file:org.glite.authz.pap.common.utils.PathNamingScheme.java
public static String[] getParentGroupChain(String groupName) { checkSyntax(groupName);/* w w w. j a va 2 s . co m*/ String[] tmp = groupName.split("/"); String[] groupChain = (String[]) ArrayUtils.subarray(tmp, 1, tmp.length); if (groupChain.length == 1) { return new String[] { groupName }; } String[] result = new String[groupChain.length - 1]; if (result.length == 1) { result[0] = "/" + groupChain[0]; return result; } for (int i = groupChain.length - 1; i > 0; i--) result[i - 1] = "/" + StringUtils.join(ArrayUtils.subarray(groupChain, 0, i), "/"); return result; }