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.marketcetera.util.unicode.FileEncoderFileTest.java
@Override protected void testEncode(final Reader reader, SignatureCharset sc, byte[] bytes, String string) throws Exception { super.testEncode(reader, sc, bytes, string); int halfLength = string.length() / 2; String firstPart = string.substring(0, halfLength); String secondPart = string.substring(halfLength); encode(new WriterCreator() { @Override/*from w ww . ja v a 2 s .com*/ public UnicodeFileWriter create() throws Exception { return new UnicodeFileWriter(new File(TEST_FILE), false, reader); } }, sc, sc, firstPart); assertArrayEquals(bytes, encode(new WriterCreator() { @Override public UnicodeFileWriter create() throws Exception { return new UnicodeFileWriter(new File(TEST_FILE), true, reader); } }, sc, sc, secondPart)); Deleter.apply(TEST_FILE); CopyBytesUtils.copy(ArrayUtils.EMPTY_BYTE_ARRAY, TEST_FILE); assertArrayEquals(bytes, encode(new WriterCreator() { @Override public UnicodeFileWriter create() throws Exception { return new UnicodeFileWriter(new File(TEST_FILE), true, reader); } }, sc, sc, string)); }
From source file:org.marketcetera.util.unicode.FileEncoderStringTest.java
@Override protected void testEncode(byte[] bytes, String string) throws Exception { super.testEncode(bytes, string); int halfLength = string.length() / 2; String firstPart = string.substring(0, halfLength); String secondPart = string.substring(halfLength); encode(new WriterCreator() { @Override//from ww w. j a va 2 s .co m public UnicodeFileWriter create() throws Exception { return new UnicodeFileWriter(TEST_FILE, false); } }, null, null, firstPart); assertArrayEquals(bytes, encode(new WriterCreator() { @Override public UnicodeFileWriter create() throws Exception { return new UnicodeFileWriter(TEST_FILE, true); } }, null, null, secondPart)); Deleter.apply(TEST_FILE); CopyBytesUtils.copy(ArrayUtils.EMPTY_BYTE_ARRAY, TEST_FILE); assertArrayEquals(bytes, encode(new WriterCreator() { @Override public UnicodeFileWriter create() throws Exception { return new UnicodeFileWriter(TEST_FILE, true); } }, null, null, string)); }
From source file:org.marketcetera.util.unicode.FileEncoderStringTest.java
@Override protected void testEncode(final SignatureCharset sc, byte[] bytes, String string) throws Exception { super.testEncode(sc, bytes, string); int halfLength = string.length() / 2; String firstPart = string.substring(0, halfLength); String secondPart = string.substring(halfLength); encode(new WriterCreator() { @Override/* w w w.ja va 2 s. c o m*/ public UnicodeFileWriter create() throws Exception { return new UnicodeFileWriter(TEST_FILE, false, sc); } }, sc, sc, firstPart); assertArrayEquals(bytes, encode(new WriterCreator() { @Override public UnicodeFileWriter create() throws Exception { return new UnicodeFileWriter(TEST_FILE, true, sc); } }, sc, sc, secondPart)); Deleter.apply(TEST_FILE); CopyBytesUtils.copy(ArrayUtils.EMPTY_BYTE_ARRAY, TEST_FILE); assertArrayEquals(bytes, encode(new WriterCreator() { @Override public UnicodeFileWriter create() throws Exception { return new UnicodeFileWriter(TEST_FILE, true, sc); } }, sc, sc, string)); }
From source file:org.marketcetera.util.unicode.FileEncoderStringTest.java
@Override protected void testEncode(final Reader reader, SignatureCharset sc, byte[] bytes, String string) throws Exception { super.testEncode(reader, sc, bytes, string); int halfLength = string.length() / 2; String firstPart = string.substring(0, halfLength); String secondPart = string.substring(halfLength); encode(new WriterCreator() { @Override/*from w w w. j a v a 2 s .c o m*/ public UnicodeFileWriter create() throws Exception { return new UnicodeFileWriter(TEST_FILE, false, reader); } }, sc, sc, firstPart); assertArrayEquals(bytes, encode(new WriterCreator() { @Override public UnicodeFileWriter create() throws Exception { return new UnicodeFileWriter(TEST_FILE, true, reader); } }, sc, sc, secondPart)); Deleter.apply(TEST_FILE); CopyBytesUtils.copy(ArrayUtils.EMPTY_BYTE_ARRAY, TEST_FILE); assertArrayEquals(bytes, encode(new WriterCreator() { @Override public UnicodeFileWriter create() throws Exception { return new UnicodeFileWriter(TEST_FILE, true, reader); } }, sc, sc, string)); }
From source file:org.marketcetera.util.unicode.ReaderTest.java
@Test public void emptyReader() throws Exception { CloseableRegistry r = new CloseableRegistry(); r = new CloseableRegistry(); try {/* w w w . j a v a 2 s .c om*/ ByteArrayInputStream is = new ByteArrayInputStream(ArrayUtils.EMPTY_BYTE_ARRAY); r.register(new InputStreamWrapper(is)); UnicodeInputStreamReader reader = new UnicodeInputStreamReader(is); r.register(new ReaderWrapper(reader)); assertNull(reader.getDecodingStrategy()); assertNull(reader.getRequestedSignatureCharset()); assertNull(reader.getSignatureCharset()); assertFalse(reader.ready()); assertFalse(reader.markSupported()); try { reader.mark(0); fail(); } catch (IOException ex) { // Desired. } try { reader.reset(); fail(); } catch (IOException ex) { // Desired. } assertEquals(-1, reader.read()); char[] charArray = new char[1]; assertEquals(-1, reader.read(charArray)); charArray = new char[3]; assertEquals(-1, reader.read(charArray, 1, 1)); CharBuffer charBuffer = CharBuffer.allocate(10); assertEquals(-1, reader.read(charBuffer)); reader.close(); reader.close(); // Ensure that close() has closed the stream, by trying to // read from the reader: this is not testing whether // read() fails; it tests whether close() worked. try { reader.read(); fail(); } catch (IOException ex) { // Desired. } try { reader.ready(); fail(); } catch (IOException ex) { // Desired. } } finally { r.close(); } }
From source file:org.marketcetera.util.unicode.WriterTest.java
@Test public void writer() throws Exception { CloseableRegistry r = new CloseableRegistry(); try {/* www . j av a 2 s .c o m*/ ByteArrayOutputStream os = new ByteArrayOutputStream(); r.register(new OutputStreamWrapper(os)); UnicodeOutputStreamWriter writer = new UnicodeOutputStreamWriter(os); r.register(new WriterWrapper(writer)); assertNull(writer.getRequestedSignatureCharset()); assertNull(writer.getSignatureCharset()); assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, os.toByteArray()); writer.write('a'); writer.flush(); assertEquals("a", new String(os.toByteArray())); writer.write(new char[] { 'b', 'c' }); writer.flush(); assertEquals("abc", new String(os.toByteArray())); writer.write(new char[] { 'b', 'd', 'e', 'f' }, 1, 2); writer.flush(); assertEquals("abcde", new String(os.toByteArray())); writer.write("fg"); writer.flush(); assertEquals("abcdefg", new String(os.toByteArray())); writer.write("ghij", 1, 2); writer.flush(); assertEquals("abcdefghi", new String(os.toByteArray())); writer.append("jk"); writer.flush(); assertEquals("abcdefghijk", new String(os.toByteArray())); writer.append("klmn", 1, 3); writer.flush(); assertEquals("abcdefghijklm", new String(os.toByteArray())); writer.append('n'); writer.flush(); assertEquals("abcdefghijklmn", new String(os.toByteArray())); writer.close(); writer.close(); // Ensure that close() has closed the stream, by trying to // write to the writer: this is not testing whether // write() fails; it tests whether close() worked. try { writer.write('a'); fail(); } catch (IOException ex) { // Desired. } } finally { r.close(); } }
From source file:org.marketcetera.util.ws.wrappers.DualWrapperTest.java
@Test public void all() throws Exception { dual(new TestWrapper(TEST_VALUE), new TestWrapper(TEST_VALUE), new TestWrapper(), new TestWrapper(null), TEST_VALUE, HELLO_EN, HELLO_EN_NAT); TestWrapper wrapper = new TestWrapper(TEST_VALUE); assertEquals(TEST_VALUE, wrapper.getRaw()); wrapper.setMarshalled(ArrayUtils.EMPTY_BYTE_ARRAY); assertNull(wrapper.getRaw());/*from ww w. j a v a 2s . com*/ assertNull(wrapper.getMarshalled()); wrapper = new TestWrapper(TEST_VALUE); wrapper.setRaw(StringUtils.EMPTY); assertNull(wrapper.getRaw()); assertNull(wrapper.getMarshalled()); }
From source file:org.marketcetera.util.ws.wrappers.WrapperTestBase.java
protected <T extends Serializable> void serialization(SerWrapper<T> wrapper, SerWrapper<T> copy, SerWrapper<T> empty, SerWrapper<T> nullArg, String stringValue, T value, T unserializableValue, String category) throws Exception { dual(wrapper, copy, empty, nullArg, stringValue, value, SerializationUtils.serialize(value)); assertNull(wrapper.getSerializationException()); assertNull(wrapper.getDeserializationException()); prepareSerWrapperFailure(category);//from ww w. java 2s.co m wrapper.setRaw(unserializableValue); assertSerWrapperSerFailure(wrapper, category); prepareSerWrapperFailure(category); wrapper.setMarshalled(ArrayUtils.EMPTY_BYTE_ARRAY); assertSerWrapperDeSerFailure(wrapper, category); }
From source file:org.nuxeo.opensocial.shindig.gadgets.NXHttpFetcher.java
/** * @param httpMethod//w w w.j a v a 2 s . c o m * @param responseCode * @return A HttpResponse object made by consuming the response of the given * HttpMethod. * @throws java.io.IOException */ private HttpResponse makeResponse(HttpMethod httpMethod, int responseCode) throws IOException { Map<String, String> headers = Maps.newHashMap(); if (httpMethod.getResponseHeaders() != null) { for (Header h : httpMethod.getResponseHeaders()) { headers.put(h.getName(), h.getValue()); } } // The first header is always null here to provide the response body. headers.remove(null); // Find the response stream - the error stream may be valid in cases // where the input stream is not. InputStream responseBodyStream = null; try { responseBodyStream = httpMethod.getResponseBodyAsStream(); } catch (IOException e) { // normal for 401, 403 and 404 responses, for example... } if (responseBodyStream == null) { // Fall back to zero length response. responseBodyStream = new ByteArrayInputStream(ArrayUtils.EMPTY_BYTE_ARRAY); } String encoding = headers.get("Content-Encoding"); // Create the appropriate stream wrapper based on the encoding type. InputStream is = responseBodyStream; if (encoding == null) { is = responseBodyStream; } else if (encoding.equalsIgnoreCase("gzip")) { is = new GZIPInputStream(responseBodyStream); } else if (encoding.equalsIgnoreCase("deflate")) { Inflater inflater = new Inflater(true); is = new InflaterInputStream(responseBodyStream, inflater); } ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; int totalBytesRead = 0; int currentBytesRead; while ((currentBytesRead = is.read(buffer)) != -1) { output.write(buffer, 0, currentBytesRead); totalBytesRead += currentBytesRead; if (maxObjSize > 0 && totalBytesRead > maxObjSize) { IOUtils.closeQuietly(is); IOUtils.closeQuietly(output); // Exceeded max # of bytes return HttpResponse.badrequest("Exceeded maximum number of bytes - " + this.maxObjSize); } } return new HttpResponseBuilder().setHttpStatusCode(responseCode).setResponse(output.toByteArray()) .addHeaders(headers).create(); }
From source file:org.onehippo.forge.hst.pdf.renderer.servlet.ContentCapturingHttpServletResponse.java
public byte[] toByteArray() { if (byteOutputBuffer != null) { return byteOutputBuffer.toByteArray(); }/*w w w.ja v a 2s . c om*/ return ArrayUtils.EMPTY_BYTE_ARRAY; }