List of usage examples for java.util Arrays copyOfRange
public static boolean[] copyOfRange(boolean[] original, int from, int to)
From source file:com.joyent.manta.client.multipart.ServerSideMultipartManagerIT.java
public final void canUploadWithByteArrayAndMultipleParts() throws IOException { final String name = UUID.randomUUID().toString(); final String path = testPathPrefix + name; final byte[] content = RandomUtils.nextBytes(FIVE_MB + 1024); final byte[] content1 = Arrays.copyOfRange(content, 0, FIVE_MB + 1); final byte[] content2 = Arrays.copyOfRange(content, FIVE_MB + 1, FIVE_MB + 1024); String contentType = "application/something-never-seen-before; charset=UTF-8"; MantaHttpHeaders headers = new MantaHttpHeaders(); headers.setContentType(contentType); ServerSideMultipartUpload upload = multipart.initiateUpload(path, null, headers); MantaMultipartUploadPart part1 = multipart.uploadPart(upload, 1, content1); MantaMultipartUploadPart part2 = multipart.uploadPart(upload, 2, content2); MantaMultipartUploadTuple[] parts = new MantaMultipartUploadTuple[] { part1, part2 }; Stream<MantaMultipartUploadTuple> partsStream = Arrays.stream(parts); multipart.complete(upload, partsStream); try (MantaObjectInputStream in = mantaClient.getAsInputStream(path); ByteArrayOutputStream out = new ByteArrayOutputStream()) { IOUtils.copy(in, out);/* w w w.j a v a2 s. c om*/ AssertJUnit.assertArrayEquals("Uploaded multipart data doesn't equal actual object data", content, out.toByteArray()); Assert.assertEquals(in.getContentType(), contentType, "Set content-type doesn't match actual content type"); } }
From source file:com.unister.semweb.drums.api.DRUMSTest.java
/** * Writes several elements of the same range to the drum and reads the drum. * // w w w. j av a 2s .co m * @throws Exception */ @Test public void readTestSeveralElements() throws Exception { DummyKVStorable[] testdata = TestUtils.createDummyData(10); DRUMS<DummyKVStorable> table = DRUMSInstantiator.createTable(hashFunction, TestUtils.gp); table.insertOrMerge(testdata); table.close(); List<DummyKVStorable> selectedData = table.read(1, 0, 10); DummyKVStorable[] result = selectedData.toArray(new DummyKVStorable[selectedData.size()]); Arrays.sort(testdata, new AbstractKVStorableComparator()); Assert.assertArrayEquals(testdata, result); List<DummyKVStorable> selectedData2 = table.read(1, 5, 10); DummyKVStorable[] result2 = selectedData2.toArray(new DummyKVStorable[selectedData2.size()]); Arrays.sort(testdata, new AbstractKVStorableComparator()); Assert.assertArrayEquals(Arrays.copyOfRange(testdata, 5, 10), result2); }
From source file:net.netheos.pcsapi.providers.BasicTest.java
@Test public void testFileOperations() throws Exception { // We'll use a temp folder for tests CPath tempRootPath = MiscUtils.generateTestPath(null); LOGGER.info("Will use test folder : {}", tempRootPath); // Create a sub-folder : CPath subPath = tempRootPath.add("sub_folder"); LOGGER.info("Creating sub_folder : {}", subPath); assertTrue(storage.createFolder(subPath)); // True because actually created assertFalse(storage.createFolder(subPath)); // False because not created // Check back : CFile subFolder = storage.getFile(subPath); assertEquals(subPath, subFolder.getPath()); assertTrue(subFolder.isFolder());//w ww .j a v a2 s .co m assertFalse(subFolder.isBlob()); if (subFolder.getModificationDate() != null) { // Not all providers have a modif time on folders MiscUtils.assertDatetimeIsAlmostNow(subFolder.getModificationDate()); } // Upload 2 files into this sub-folder : CPath fpath1 = subPath.add("a_test_file1"); byte[] contentFile1 = "This is binary contnt of test file 1...".getBytes(PcsUtils.UTF8); LOGGER.info("Uploading blob to : {}", fpath1); CUploadRequest uploadRequest = new CUploadRequest(fpath1, new MemoryByteSource(contentFile1)); storage.upload(uploadRequest); CPath fpath2 = subPath.add("a_test_file2"); // Generate a quite big random data : byte[] contentFile2 = MiscUtils.generateRandomByteArray(500000, null); LOGGER.info("Uploading blob to : {}", fpath2); uploadRequest = new CUploadRequest(fpath2, new MemoryByteSource(contentFile2)); storage.upload(uploadRequest); // Check uploaded blobs informations : // we check file2 first because has just been uploaded / for modif time check CFile cblob = storage.getFile(fpath2); assertTrue(cblob.isBlob()); assertFalse(cblob.isFolder()); assertEquals(contentFile2.length, ((CBlob) cblob).length()); MiscUtils.assertDatetimeIsAlmostNow(cblob.getModificationDate()); cblob = storage.getFile(fpath1); assertTrue(cblob.isBlob()); assertFalse(cblob.isFolder()); assertEquals(contentFile1.length, ((CBlob) cblob).length()); // Download data, and check : LOGGER.info("Downloading back and checking file : {}", fpath1); MemoryByteSink mbs = new MemoryByteSink(); CDownloadRequest downloadRequest = new CDownloadRequest(fpath1, mbs); storage.download(downloadRequest); assertArrayEquals(contentFile1, mbs.getData()); // Check also with different Ranges: LOGGER.info("Downloading back and checking file ranges: {}", fpath1); downloadRequest.setRange(5, -1); // starting at offset 5 storage.download(downloadRequest); assertArrayEquals(Arrays.copyOfRange(contentFile1, 5, contentFile1.length), mbs.getData()); downloadRequest.setRange(-1, 5); // last 5 bytes storage.download(downloadRequest); assertArrayEquals(Arrays.copyOfRange(contentFile1, contentFile1.length - 5, contentFile1.length), mbs.getData()); downloadRequest.setRange(2, 5); // 5 bytes at offset 2 storage.download(downloadRequest); assertArrayEquals(Arrays.copyOfRange(contentFile1, 2, 7), mbs.getData()); LOGGER.info("Downloading back and checking file : {}", fpath2); downloadRequest = new CDownloadRequest(fpath2, mbs); storage.download(downloadRequest); assertArrayEquals(contentFile2, mbs.getData()); // Check that if we upload again, blob is replaced : LOGGER.info("Checking file overwrite : {}", fpath2); contentFile2 = MiscUtils.generateRandomByteArray(300000, null); uploadRequest = new CUploadRequest(fpath2, new MemoryByteSource(contentFile2)); storage.upload(uploadRequest); storage.download(downloadRequest); assertArrayEquals(contentFile2, mbs.getData()); // Check that we can replace replace existing blob with empty content: LOGGER.info("Checking file overwrite with empty file: {}", fpath2); contentFile2 = new byte[0]; uploadRequest = new CUploadRequest(fpath2, new MemoryByteSource(contentFile2)); storage.upload(uploadRequest); storage.download(downloadRequest); assertArrayEquals(contentFile2, mbs.getData()); // Create a sub_sub_folder : CPath subSubPath = subPath.add("a_sub_sub_folder"); LOGGER.info("Creating sub_sub folder : {}", subSubPath); storage.createFolder(subSubPath); LOGGER.info("Check uploaded blobs and sub_sub_folder all appear in folder list"); CFolderContent folderContent = storage.listFolder((CFolder) subFolder); LOGGER.info("sub_folder contains files : {}", folderContent); // It happened once here that hubic did not list fpath1 'a_test_file1' in folder_content : // only 2 files were present ?! assertEquals(3, folderContent.size()); assertTrue(folderContent.containsPath(fpath1)); assertTrue(folderContent.getFile(fpath1).isBlob()); assertFalse(folderContent.getFile(fpath1).isFolder()); assertTrue(folderContent.containsPath(fpath2)); assertTrue(folderContent.getFile(fpath2).isBlob()); assertFalse(folderContent.getFile(fpath2).isFolder()); assertTrue(folderContent.containsPath(subSubPath)); assertFalse(folderContent.getFile(subSubPath).isBlob()); assertTrue(folderContent.getFile(subSubPath).isFolder()); LOGGER.info("Check that list of sub_sub folder is empty : {}", subSubPath); assertTrue(storage.listFolder(subSubPath).isEmpty()); LOGGER.info("Check that listing content of a blob raises : {}", fpath1); try { storage.listFolder(fpath1); fail("Listing a blob should raise"); } catch (CInvalidFileTypeException ex) { assertEquals(fpath1, ex.getPath()); assertFalse(ex.isBlobExpected()); } LOGGER.info("Delete file1 : {}", fpath1); assertTrue(storage.delete(fpath1)); // We have deleted the file assertFalse(storage.delete(fpath1)); // We have not deleted anything LOGGER.info("Check file1 does not appear anymore in folder : {}", subFolder); assertFalse(storage.listFolder((CFolder) subFolder).containsPath(fpath1)); assertNull(storage.getFile(fpath1)); LOGGER.info("Delete whole test folder : {}", tempRootPath); boolean ret = storage.delete(tempRootPath); assertTrue(ret); // We have deleted at least one file LOGGER.info("Deleting again returns False"); ret = storage.delete(tempRootPath); assertFalse(ret); // We have not deleted anything LOGGER.info("Listing a deleted folder returns None : {}", tempRootPath); assertNull(storage.listFolder(tempRootPath)); assertNull(storage.getFile(tempRootPath)); }
From source file:ffx.potential.bonded.SturmMethod.java
/** * Build up a sturm sequence for a polynomial, and return the number of * polynomials in the sequence.//from www. j a va 2s .co m * * @param ord * @param sseq * @return the number of polynomials in the sequence. */ private int buildSturm(int ord, Polynomial[] sseq) { double f; double[] fp; double[] fc; sseq[0].order = ord; sseq[1].order = ord - 1; // Calculate the derivative and normalise the leading coefficient f = abs(sseq[0].coefficients[ord] * ord); fp = sseq[1].coefficients; fc = Arrays.copyOfRange(sseq[0].coefficients, 1, sseq[0].coefficients.length); int j = 0; for (int i = 1; i <= ord; i++) { fp[j] = fc[j] * i / f; j++; } // Construct the rest of the Sturm sequence. (Double check this... ) int i; for (i = 0; i < sseq[0].coefficients.length - 2 && modp(sseq[i], sseq[i + 1], sseq[i + 2]); i++) { //reverse the sign and normalise f = -Math.abs(sseq[i + 2].coefficients[sseq[i + 2].order]); for (j = sseq[i + 2].order; j >= 0; j--) { sseq[i + 2].coefficients[j] /= f; } } // Reverse the sign. sseq[i + 2].coefficients[0] = -sseq[i + 2].coefficients[0]; return (sseq[0].order - sseq[i + 2].order); }
From source file:com.netflix.imfutility.ttmltostl.stl.StlTtiTest.java
/** * Each text must end with 0x8f!/*ww w .j av a 2s . co m*/ * * @throws Exception */ @Test public void testTextEndsWith8H() throws Exception { // prepare long subtitles, so that one subtitles is stored in two tti blocks TimedTextObject tto = StlTestUtil.buildTto("10:00:00:00", "10:00:05:00", StringUtils.rightPad("", 111, '1'), // 1 block "10:00:05:00", "10:00:10:00", StringUtils.rightPad("", 112, '2'), // 2 blocks "10:00:10:00", "10:00:15:00", StringUtils.rightPad("", 222, '3'), // 2 blocks "10:00:15:00", "10:00:20:00", StringUtils.rightPad("", 223, '4') // 3 blocks ); byte[][] stl = StlTestUtil.build(tto, StlTestUtil.getMetadataXml()); byte[] tti = stl[1]; // 1st subtitle - 1 block int offset = 128; // subtitle zero byte[] textWithPadding = new byte[112]; Arrays.fill(textWithPadding, (byte) 0x31); textWithPadding[111] = (byte) 0x8f; assertArrayEquals(new byte[] { 0x01, 0x00, // subtitle number - 1 (byte) 0xff, // extension block - last }, Arrays.copyOfRange(tti, offset + 1, offset + 4)); assertArrayEquals(textWithPadding, Arrays.copyOfRange(tti, offset + 16, offset + 128)); // 2d subtitle - 2 blocks offset += 128; textWithPadding = new byte[112]; Arrays.fill(textWithPadding, (byte) 0x32); textWithPadding[111] = (byte) 0x8f; assertArrayEquals(new byte[] { 0x02, 0x00, // subtitle number - 2 (byte) 0x00, // extension block - 1st }, Arrays.copyOfRange(tti, offset + 1, offset + 4)); assertArrayEquals(textWithPadding, Arrays.copyOfRange(tti, offset + 16, offset + 128)); offset += 128; textWithPadding = new byte[112]; Arrays.fill(textWithPadding, (byte) 0x8f); textWithPadding[0] = (byte) 0x32; assertArrayEquals(new byte[] { 0x02, 0x00, // subtitle number - 2 (byte) 0xff, // extension block - last }, Arrays.copyOfRange(tti, offset + 1, offset + 4)); assertArrayEquals(textWithPadding, Arrays.copyOfRange(tti, offset + 16, offset + 128)); // 3d subtitle - 2 blocks offset += 128; textWithPadding = new byte[112]; Arrays.fill(textWithPadding, (byte) 0x33); textWithPadding[111] = (byte) 0x8f; assertArrayEquals(new byte[] { 0x03, 0x00, // subtitle number - 3 (byte) 0x00, // extension block - 1st }, Arrays.copyOfRange(tti, offset + 1, offset + 4)); assertArrayEquals(textWithPadding, Arrays.copyOfRange(tti, offset + 16, offset + 128)); offset += 128; assertArrayEquals(new byte[] { 0x03, 0x00, // subtitle number - 3 (byte) 0xff, // extension block - last }, Arrays.copyOfRange(tti, offset + 1, offset + 4)); assertArrayEquals(textWithPadding, Arrays.copyOfRange(tti, offset + 16, offset + 128)); // 4th subtitle - 3 blocks offset += 128; textWithPadding = new byte[112]; Arrays.fill(textWithPadding, (byte) 0x34); textWithPadding[111] = (byte) 0x8f; assertArrayEquals(new byte[] { 0x04, 0x00, // subtitle number - 4 (byte) 0x00, // extension block - 1st }, Arrays.copyOfRange(tti, offset + 1, offset + 4)); assertArrayEquals(textWithPadding, Arrays.copyOfRange(tti, offset + 16, offset + 128)); offset += 128; assertArrayEquals(new byte[] { 0x04, 0x00, // subtitle number - 4 (byte) 0x01, // extension block - last }, Arrays.copyOfRange(tti, offset + 1, offset + 4)); assertArrayEquals(textWithPadding, Arrays.copyOfRange(tti, offset + 16, offset + 128)); offset += 128; textWithPadding = new byte[112]; Arrays.fill(textWithPadding, (byte) 0x8f); textWithPadding[0] = (byte) 0x34; assertArrayEquals(new byte[] { 0x04, 0x00, // subtitle number - 4 (byte) 0xff, // extension block - last }, Arrays.copyOfRange(tti, offset + 1, offset + 4)); assertArrayEquals(textWithPadding, Arrays.copyOfRange(tti, offset + 16, offset + 128)); }