GEODE-2995: more review feedback and spotlessApply Signed-off-by: Brian Rowe <br...@pivotal.io>
Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/0de1d97e Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/0de1d97e Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/0de1d97e Branch: refs/heads/feature/GEODE-2804v3 Commit: 0de1d97ea229ec43203437f58971c44fe37cef62 Parents: 31f4de0 Author: Galen O'Sullivan <gosulli...@pivotal.io> Authored: Tue Jun 20 16:58:51 2017 -0700 Committer: Hitesh Khamesra <hkhame...@pivotal.io> Committed: Mon Jun 26 09:26:22 2017 -0700 ---------------------------------------------------------------------- .../protocol/operations/OperationHandler.java | 20 ++++++++++++------ ...rationHandlerAlreadyRegisteredException.java | 3 ++- .../protocol/protobuf/ProtobufOpsProcessor.java | 22 ++++++++++---------- .../protobuf/ProtobufStreamProcessor.java | 7 +++++-- .../protocol/serializer/ProtocolSerializer.java | 1 + .../serialization/SerializationService.java | 7 ++++++- .../geode/serialization/SerializationType.java | 3 +++ .../apache/geode/serialization/TypeCodec.java | 10 +++++++++ .../exception/TypeEncodingException.java | 21 +++++++++++++++++++ .../UnsupportedEncodingTypeException.java | 2 +- .../CodecAlreadyRegisteredForTypeException.java | 3 ++- .../CodecNotRegisteredForTypeException.java | 4 +++- .../geode/client/protocol/IntegrationTest.java | 3 +-- .../protobuf/ProtobufOpsProcessorTest.java | 10 ++++----- .../ProtobufProtocolSerializerJUnitTest.java | 2 +- 15 files changed, 86 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java index 8eab146..7683e3b 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java +++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java @@ -15,23 +15,31 @@ package org.apache.geode.protocol.operations; import org.apache.geode.cache.Cache; -import org.apache.geode.protocol.protobuf.ProtobufOpsProcessor; import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry; +import org.apache.geode.protocol.protobuf.ProtobufOpsProcessor; import org.apache.geode.serialization.SerializationService; -import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException; -import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException; +import org.apache.geode.serialization.exception.TypeEncodingException; /** - * This interface is implemented by a object capable of handling request types 'Req' and returning an a response of type 'Resp' + * This interface is implemented by a object capable of handling request types 'Req' and returning + * an a response of type 'Resp' * * See {@link ProtobufOpsProcessor} */ public interface OperationHandler<Req, Resp> { + /** + * Decode the message, deserialize contained values using the serialization service, do the work + * indicated on the provided cache, and return a response. + * + * @throws TypeEncodingException if a problem occurs decoding an encoded value contained in the + * request. + */ Resp process(SerializationService serializationService, Req request, Cache cache) - throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException; + throws TypeEncodingException; /** - * @return the magic number used for registering the operation type with the {@link OperationsHandlerRegistry}. + * @return the magic number used for registering the operation type with the + * {@link OperationsHandlerRegistry}. */ int getOperationCode(); } http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java index 519698d..18475d8 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java +++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/registry/exception/OperationHandlerAlreadyRegisteredException.java @@ -15,7 +15,8 @@ package org.apache.geode.protocol.operations.registry.exception; /** - * Indicates that an operation handler is attempting to register for an already handled operation type. + * Indicates that an operation handler is attempting to register for an already handled operation + * type. */ public class OperationHandlerAlreadyRegisteredException extends Exception { public OperationHandlerAlreadyRegisteredException(String message) { http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java index c572d80..d426149 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java +++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java @@ -20,37 +20,37 @@ import org.apache.geode.protocol.operations.OperationHandler; import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry; import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException; import org.apache.geode.serialization.SerializationService; -import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException; -import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException; +import org.apache.geode.serialization.exception.TypeEncodingException; /** - * This handles protobuf requests by determining the operation type of the request and dispatching it to the appropriate handler. + * This handles protobuf requests by determining the operation type of the request and dispatching + * it to the appropriate handler. */ public class ProtobufOpsProcessor { private final OperationsHandlerRegistry opsHandlerRegistry; private final SerializationService serializationService; public ProtobufOpsProcessor(OperationsHandlerRegistry opsHandlerRegistry, - SerializationService serializationService) { + SerializationService serializationService) { this.opsHandlerRegistry = opsHandlerRegistry; this.serializationService = serializationService; } public ClientProtocol.Response process(ClientProtocol.Request request, Cache cache) - throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException, - OperationHandlerNotRegisteredException, InvalidProtocolMessageException { + throws TypeEncodingException, OperationHandlerNotRegisteredException, + InvalidProtocolMessageException { OperationHandler opsHandler = opsHandlerRegistry - .getOperationHandlerForOperationId(request.getRequestAPICase().getNumber()); + .getOperationHandlerForOperationId(request.getRequestAPICase().getNumber()); - Object responseMessage = opsHandler.process(serializationService, - getRequestForOperationTypeID(request), cache); + Object responseMessage = + opsHandler.process(serializationService, getRequestForOperationTypeID(request), cache); return ClientProtocol.Response.newBuilder() .setGetResponse((RegionAPI.GetResponse) responseMessage).build(); } // package visibility for testing static Object getRequestForOperationTypeID(ClientProtocol.Request request) - throws InvalidProtocolMessageException { + throws InvalidProtocolMessageException { switch (request.getRequestAPICase()) { case PUTREQUEST: return request.getPutRequest(); @@ -60,7 +60,7 @@ public class ProtobufOpsProcessor { return request.getPutAllRequest(); default: throw new InvalidProtocolMessageException( - "Unknown request type: " + request.getRequestAPICase().getNumber()); + "Unknown request type: " + request.getRequestAPICase().getNumber()); } } } http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java index 41a3c40..1dcb61c 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java +++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java @@ -20,6 +20,7 @@ import org.apache.geode.protocol.protobuf.serializer.ProtobufProtocolSerializer; import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry; import org.apache.geode.protocol.operations.registry.exception.OperationHandlerAlreadyRegisteredException; import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException; +import org.apache.geode.serialization.exception.TypeEncodingException; import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException; import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException; import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException; @@ -29,7 +30,9 @@ import java.io.InputStream; import java.io.OutputStream; /** - * This object handles an incoming stream containing protobuf messages. It parses the protobuf messages, hands the requests to an appropriate handler, wraps the response in a protobuf message, and then pushes it to the output stream. + * This object handles an incoming stream containing protobuf messages. It parses the protobuf + * messages, hands the requests to an appropriate handler, wraps the response in a protobuf message, + * and then pushes it to the output stream. */ public class ProtobufStreamProcessor { ProtobufProtocolSerializer protobufProtocolSerializer; @@ -47,7 +50,7 @@ public class ProtobufStreamProcessor { public void processOneMessage(InputStream inputStream, OutputStream outputStream, Cache cache) throws InvalidProtocolMessageException, OperationHandlerNotRegisteredException, - UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException, IOException { + TypeEncodingException, IOException { ClientProtocol.Message message = protobufProtocolSerializer.deserialize(inputStream); ClientProtocol.Request request = message.getRequest(); http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/protocol/serializer/ProtocolSerializer.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/serializer/ProtocolSerializer.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/serializer/ProtocolSerializer.java index 7191d87..46e491f 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/protocol/serializer/ProtocolSerializer.java +++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/serializer/ProtocolSerializer.java @@ -22,6 +22,7 @@ import java.io.OutputStream; /** * This interface is used to translate between binary data and protocol specific messages. + * * @param <T> The message type of the protocol. */ public interface ProtocolSerializer<T> { http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationService.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationService.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationService.java index 623a7bd..cdeb170 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationService.java +++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationService.java @@ -17,8 +17,13 @@ package org.apache.geode.serialization; import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException; import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException; +/** + * This interface takes an protocol specific encodingTypeValue enum and converts between objects and + * bytes using the encodingTypeValue to decide what encoding type to use. + * + * @param <T> the enumeration of types known to a particular protocol + */ public interface SerializationService<T> { - Object decode(T encodingTypeValue, byte[] value) throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException; http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java index 4ea4422..91466a1 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java +++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/SerializationType.java @@ -16,6 +16,9 @@ package org.apache.geode.serialization; import org.apache.geode.pdx.PdxInstance; +/** + * Enumerates the serialization types currently available to wire protocols. + */ public enum SerializationType { STRING(String.class), BINARY(byte[].class), http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java index f2c7f90..8506a53 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java +++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/TypeCodec.java @@ -14,10 +14,20 @@ */ package org.apache.geode.serialization; +/** + * This interface converts a particular type to and from its binary representation. + * + * NOTE: it is expected that T will be one of the serialization types in @{@link SerializationType}. + * + * @param <T> the type this codec knows how to convert + */ public interface TypeCodec<T> { T decode(byte[] incoming); byte[] encode(T incoming); + /** + * @return the SerializationType corresponding to T + */ SerializationType getSerializationType(); } http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/TypeEncodingException.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/TypeEncodingException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/TypeEncodingException.java new file mode 100644 index 0000000..f3145a7 --- /dev/null +++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/TypeEncodingException.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.geode.serialization.exception; + +public class TypeEncodingException extends Exception { + public TypeEncodingException(String message) { + super(message); + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java index 6d2a032..c577e76 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java +++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/exception/UnsupportedEncodingTypeException.java @@ -17,7 +17,7 @@ package org.apache.geode.serialization.exception; /** * This indicates an encoding type that we don't know how to handle. */ -public class UnsupportedEncodingTypeException extends Exception { +public class UnsupportedEncodingTypeException extends TypeEncodingException { public UnsupportedEncodingTypeException(String message) { super(message); } http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java index 7e73ba9..66ae850 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java +++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java @@ -15,7 +15,8 @@ package org.apache.geode.serialization.registry.exception; /** - * This indicates that we're attempting to register a codec for a type which we already have a handler for. + * This indicates that we're attempting to register a codec for a type which we already have a + * handler for. */ public class CodecAlreadyRegisteredForTypeException extends Exception { public CodecAlreadyRegisteredForTypeException(String message) { http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java index 58cb691..5c923a5 100644 --- a/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java +++ b/geode-protobuf/src/main/java/org/apache/geode/serialization/registry/exception/CodecNotRegisteredForTypeException.java @@ -14,10 +14,12 @@ */ package org.apache.geode.serialization.registry.exception; +import org.apache.geode.serialization.exception.TypeEncodingException; + /** * This indicates we're attempting to handle a type for which we don't have a registered codec. */ -public class CodecNotRegisteredForTypeException extends Exception { +public class CodecNotRegisteredForTypeException extends TypeEncodingException { public CodecNotRegisteredForTypeException(String message) { super(message); } http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java index e32c711..63cde31 100644 --- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java +++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/IntegrationTest.java @@ -65,8 +65,7 @@ public class IntegrationTest { } @Test - public void testGetRequestProcessed() - throws Exception { + public void testGetRequestProcessed() throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ProtobufStreamProcessor streamProcessor = new ProtobufStreamProcessor(); http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java index 9298026..ac3d68f 100644 --- a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java +++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorTest.java @@ -24,6 +24,7 @@ import org.apache.geode.protocol.operations.OperationHandler; import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry; import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException; import org.apache.geode.serialization.SerializationService; +import org.apache.geode.serialization.exception.TypeEncodingException; import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException; import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException; import org.apache.geode.test.junit.categories.UnitTest; @@ -34,9 +35,8 @@ import org.junit.experimental.categories.Category; @Category(UnitTest.class) public class ProtobufOpsProcessorTest { @Test - public void testOpsProcessor() throws CodecNotRegisteredForTypeException, - OperationHandlerNotRegisteredException, UnsupportedEncodingTypeException, - InvalidProtocolMessageException { + public void testOpsProcessor() throws TypeEncodingException, + OperationHandlerNotRegisteredException, InvalidProtocolMessageException { OperationsHandlerRegistry opsHandlerRegistryStub = mock(OperationsHandlerRegistry.class); OperationHandler operationHandlerStub = mock(OperationHandler.class); SerializationService serializationServiceStub = mock(SerializationService.class); @@ -54,8 +54,8 @@ public class ProtobufOpsProcessorTest { ProtobufOpsProcessor.getRequestForOperationTypeID(messageRequest), dummyCache)) .thenReturn(expectedResponse); - ProtobufOpsProcessor - processor = new ProtobufOpsProcessor(opsHandlerRegistryStub, serializationServiceStub); + ProtobufOpsProcessor processor = + new ProtobufOpsProcessor(opsHandlerRegistryStub, serializationServiceStub); ClientProtocol.Response response = processor.process(messageRequest, dummyCache); Assert.assertEquals(expectedResponse, response.getGetResponse()); } http://git-wip-us.apache.org/repos/asf/geode/blob/0de1d97e/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java index 95244d2..e1f7b5b 100644 --- a/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java +++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/serializer/ProtobufProtocolSerializerJUnitTest.java @@ -60,7 +60,7 @@ public class ProtobufProtocolSerializerJUnitTest { @Test(expected = InvalidProtocolMessageException.class) public void testDeserializeInvalidByteThrowsException() - throws IOException, InvalidProtocolMessageException { + throws IOException, InvalidProtocolMessageException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byteArrayOutputStream.write("Some incorrect byte array".getBytes()); InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());