List of usage examples for org.apache.commons.lang ArrayUtils EMPTY_BYTE_ARRAY
null EMPTY_BYTE_ARRAY
To view the source code for org.apache.commons.lang ArrayUtils EMPTY_BYTE_ARRAY.
Click Source Link
byte
array. From source file:org.apache.shindig.common.util.StringEncoding.java
/** Decodes the given encoded string and returns the original raw bytes. */ public byte[] decode(String encoded) { if (encoded.length() == 0) { return ArrayUtils.EMPTY_BYTE_ARRAY; }/*from ww w .j ava2s . c o m*/ int encodedLength = encoded.length(); int outLength = encodedLength * SHIFT / 8; byte[] result = new byte[outLength]; int buffer = 0; int next = 0; int bitsLeft = 0; for (char c : encoded.toCharArray()) { buffer <<= SHIFT; buffer |= Arrays.binarySearch(DIGITS, c) & MASK; bitsLeft += SHIFT; if (bitsLeft >= 8) { result[next++] = (byte) (buffer >> (bitsLeft - 8)); bitsLeft -= 8; } } assert next == outLength && bitsLeft < SHIFT; return result; }
From source file:org.apache.shindig.gadgets.http.BasicHttpCacheTest.java
private HttpResponse createResponse(int statusCode, String header, String headerValue) { Map<String, List<String>> headers = new HashMap<String, List<String>>(); if (header != null) { headers.put(header, Arrays.asList(headerValue)); }// w w w.jav a 2 s . com HttpResponse resp = new HttpResponse(statusCode, ArrayUtils.EMPTY_BYTE_ARRAY, headers); return resp; }
From source file:org.apache.shindig.gadgets.http.HttpRequest.java
/** * Assigns the specified body to the request, copying all input bytes. *//*from w w w. j a v a2 s .co m*/ public HttpRequest setPostBody(byte[] postBody) { if (postBody == null) { this.postBody = ArrayUtils.EMPTY_BYTE_ARRAY; } else { this.postBody = new byte[postBody.length]; System.arraycopy(postBody, 0, this.postBody, 0, postBody.length); } return this; }
From source file:org.apache.shindig.gadgets.http.HttpResponseBuilder.java
/** * @param responseBytes The response body. Copied when set. *//*from w ww. ja v a 2 s . c o m*/ public HttpResponseBuilder setResponse(byte[] responseBytes) { if (responseBytes == null) { responseBytes = ArrayUtils.EMPTY_BYTE_ARRAY; } byte[] newBytes = new byte[responseBytes.length]; System.arraycopy(responseBytes, 0, newBytes, 0, responseBytes.length); setContentBytes(newBytes); return this; }
From source file:org.apache.shindig.gadgets.http.HttpResponseBuilder.java
/** * @param responseBytes The response body. Not copied when set. *///from w ww .j av a 2s . c o m public HttpResponseBuilder setResponseNoCopy(byte[] responseBytes) { if (responseBytes == null) { responseBytes = ArrayUtils.EMPTY_BYTE_ARRAY; } setContentBytes(responseBytes); return this; }
From source file:org.apache.shindig.gadgets.oauth.OAuthRequestTest.java
@Test(expected = RuntimeException.class) public void testGetTamperedRemoveRawContent() throws Exception { byte[] raw = { 0, 1, 2, 3, 4, 5 }; MakeRequestClient client = makeSignedFetchClient("o", "v", "http://www.example.com/app"); // Tamper with the body before it hits the service provider client.setNextFetcher(new HttpFetcher() { public HttpResponse fetch(HttpRequest request) throws GadgetException { request.setPostBody(ArrayUtils.EMPTY_BYTE_ARRAY); request.setHeader("Content-Type", "application/x-www-form-urlencoded"); return serviceProvider.fetch(request); }/*from ww w .j av a2 s . c o m*/ }); client.sendGetWithBody(FakeOAuthServiceProvider.RESOURCE_URL, "funky-content", raw); fail("Should have thrown with body hash in form encoded request"); }
From source file:org.apache.shindig.gadgets.oauth.OAuthRequestTest.java
@Test(expected = RuntimeException.class) public void testPostTamperedRemoveRawContent() throws Exception { byte[] raw = { 0, 1, 2, 3, 4, 5 }; MakeRequestClient client = makeSignedFetchClient("o", "v", "http://www.example.com/app"); // Tamper with the body before it hits the service provider client.setNextFetcher(new HttpFetcher() { public HttpResponse fetch(HttpRequest request) throws GadgetException { request.setPostBody(ArrayUtils.EMPTY_BYTE_ARRAY); request.setHeader("Content-Type", "application/x-www-form-urlencoded"); return serviceProvider.fetch(request); }/* w w w . j a va 2 s . co m*/ }); client.sendRawPost(FakeOAuthServiceProvider.RESOURCE_URL, "funky-content", raw); fail("Should have thrown with body hash in form encoded request"); }
From source file:org.eclipse.wb.internal.core.databinding.ui.editor.contentproviders.TreeTransfer.java
@Override protected Object nativeToJava(TransferData transferData) { return ArrayUtils.EMPTY_BYTE_ARRAY; }
From source file:org.janusgraph.diskstorage.cassandra.embedded.CassandraEmbeddedKeyColumnValueStore.java
/** * Create a RangeSliceCommand and run it against the StorageProxy. * <p>//from w w w . j a va 2s . c o m * To match the behavior of the standard Cassandra thrift API endpoint, the * {@code nowMillis} argument should be the number of milliseconds since the * UNIX Epoch (e.g. System.currentTimeMillis() or equivalent obtained * through a {@link TimestampProvider}). This is per * {@link org.apache.cassandra.thrift.CassandraServer#get_range_slices(ColumnParent, SlicePredicate, KeyRange, ConsistencyLevel)}, * which passes the server's System.currentTimeMillis() to the * {@code RangeSliceCommand} constructor. */ private List<Row> getKeySlice(Token start, Token end, @Nullable SliceQuery sliceQuery, int pageSize, long nowMillis) throws BackendException { IPartitioner partitioner = StorageService.getPartitioner(); SliceRange columnSlice = new SliceRange(); if (sliceQuery == null) { columnSlice.setStart(ArrayUtils.EMPTY_BYTE_ARRAY).setFinish(ArrayUtils.EMPTY_BYTE_ARRAY).setCount(5); } else { columnSlice.setStart(sliceQuery.getSliceStart().asByteBuffer()) .setFinish(sliceQuery.getSliceEnd().asByteBuffer()) .setCount(sliceQuery.hasLimit() ? sliceQuery.getLimit() : Integer.MAX_VALUE); } /* Note: we need to fetch columns for each row as well to remove "range ghosts" */ SlicePredicate predicate = new SlicePredicate().setSlice_range(columnSlice); RowPosition startPosition = start.minKeyBound(partitioner); RowPosition endPosition = end.minKeyBound(partitioner); List<Row> rows; try { CFMetaData cfm = Schema.instance.getCFMetaData(keyspace, columnFamily); IDiskAtomFilter filter = ThriftValidation.asIFilter(predicate, cfm, null); RangeSliceCommand cmd = new RangeSliceCommand(keyspace, columnFamily, nowMillis, filter, new Bounds<RowPosition>(startPosition, endPosition), pageSize); rows = StorageProxy.getRangeSlice(cmd, ConsistencyLevel.QUORUM); } catch (Exception e) { throw new PermanentBackendException(e); } return rows; }
From source file:org.janusgraph.diskstorage.cassandra.thrift.CassandraThriftKeyColumnValueStore.java
private List<KeySlice> getRangeSlices(org.apache.cassandra.thrift.KeyRange keyRange, @Nullable SliceQuery sliceQuery) throws BackendException { SliceRange sliceRange = new SliceRange(); if (sliceQuery == null) { sliceRange.setStart(ArrayUtils.EMPTY_BYTE_ARRAY).setFinish(ArrayUtils.EMPTY_BYTE_ARRAY).setCount(5); } else {/*from w ww.ja va 2 s . c om*/ sliceRange.setStart(sliceQuery.getSliceStart().asByteBuffer()) .setFinish(sliceQuery.getSliceEnd().asByteBuffer()) .setCount((sliceQuery.hasLimit()) ? sliceQuery.getLimit() : Integer.MAX_VALUE); } CTConnection connection = null; try { connection = pool.borrowObject(keyspace); List<KeySlice> slices = connection.getClient().get_range_slices(new ColumnParent(columnFamily), new SlicePredicate().setSlice_range(sliceRange), keyRange, ConsistencyLevel.QUORUM); for (KeySlice s : slices) { logger.debug("Key {}", ByteBufferUtil.toString(s.key, "-")); } /* Note: we need to fetch columns for each row as well to remove "range ghosts" */ List<KeySlice> result = new ArrayList<>(slices.size()); KeyIterationPredicate pred = new KeyIterationPredicate(); for (KeySlice ks : slices) if (pred.apply(ks)) result.add(ks); return result; } catch (Exception e) { throw convertException(e); } finally { if (connection != null) pool.returnObjectUnsafe(keyspace, connection); } }