org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream Java Examples

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NettyMessage.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
static ErrorResponse readFrom(ByteBuf buffer) throws Exception {
	try (ObjectInputStream ois = new ObjectInputStream(new ByteBufInputStream(buffer))) {
		Object obj = ois.readObject();

		if (!(obj instanceof Throwable)) {
			throw new ClassCastException("Read object expected to be of type Throwable, " +
					"actual type is " + obj.getClass() + ".");
		} else {
			if (buffer.readBoolean()) {
				InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
				return new ErrorResponse((Throwable) obj, receiverId);
			} else {
				return new ErrorResponse((Throwable) obj);
			}
		}
	}
}
 
Example #2
Source File: NettyMessage.java    From flink with Apache License 2.0 6 votes vote down vote up
static ErrorResponse readFrom(ByteBuf buffer) throws Exception {
	try (ObjectInputStream ois = new ObjectInputStream(new ByteBufInputStream(buffer))) {
		Object obj = ois.readObject();

		if (!(obj instanceof Throwable)) {
			throw new ClassCastException("Read object expected to be of type Throwable, " +
					"actual type is " + obj.getClass() + ".");
		} else {
			if (buffer.readBoolean()) {
				InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
				return new ErrorResponse((Throwable) obj, receiverId);
			} else {
				return new ErrorResponse((Throwable) obj);
			}
		}
	}
}
 
Example #3
Source File: NettyMessage.java    From flink with Apache License 2.0 6 votes vote down vote up
static ErrorResponse readFrom(ByteBuf buffer) throws Exception {
	try (ObjectInputStream ois = new ObjectInputStream(new ByteBufInputStream(buffer))) {
		Object obj = ois.readObject();

		if (!(obj instanceof Throwable)) {
			throw new ClassCastException("Read object expected to be of type Throwable, " +
					"actual type is " + obj.getClass() + ".");
		} else {
			if (buffer.readBoolean()) {
				InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
				return new ErrorResponse((Throwable) obj, receiverId);
			} else {
				return new ErrorResponse((Throwable) obj);
			}
		}
	}
}
 
Example #4
Source File: RestClient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void readRawResponse(FullHttpResponse msg) {
	ByteBuf content = msg.content();

	JsonNode rawResponse;
	try (InputStream in = new ByteBufInputStream(content)) {
		rawResponse = objectMapper.readTree(in);
		LOG.debug("Received response {}.", rawResponse);
	} catch (JsonProcessingException je) {
		LOG.error("Response was not valid JSON.", je);
		// let's see if it was a plain-text message instead
		content.readerIndex(0);
		try (ByteBufInputStream in = new ByteBufInputStream(content)) {
			byte[] data = new byte[in.available()];
			in.readFully(data);
			String message = new String(data);
			LOG.error("Unexpected plain-text response: {}", message);
			jsonFuture.completeExceptionally(new RestClientException("Response was not valid JSON, but plain-text: " + message, je, msg.getStatus()));
		} catch (IOException e) {
			jsonFuture.completeExceptionally(new RestClientException("Response was not valid JSON, nor plain-text.", je, msg.getStatus()));
		}
		return;
	} catch (IOException ioe) {
		LOG.error("Response could not be read.", ioe);
		jsonFuture.completeExceptionally(new RestClientException("Response could not be read.", ioe, msg.getStatus()));
		return;
	}
	jsonFuture.complete(new JsonResponse(rawResponse, msg.getStatus()));
}
 
Example #5
Source File: MessageSerializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * De-serializes the {@link RequestFailure} sent to the
 * {@link org.apache.flink.queryablestate.network.Client} in case of
 * protocol related errors.
 * <pre>
 *  <b>The buffer is expected to be at the correct position.</b>
 * </pre>
 * @param buf	The {@link ByteBuf} containing the serialized failure message.
 * @return		The failure message.
 */
public static RequestFailure deserializeRequestFailure(final ByteBuf buf) throws IOException, ClassNotFoundException {
	long requestId = buf.readLong();

	Throwable cause;
	try (ByteBufInputStream bis = new ByteBufInputStream(buf);
			ObjectInputStream in = new ObjectInputStream(bis)) {
		cause = (Throwable) in.readObject();
	}
	return new RequestFailure(requestId, cause);
}
 
Example #6
Source File: RestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
private void readRawResponse(FullHttpResponse msg) {
	ByteBuf content = msg.content();

	JsonNode rawResponse;
	try (InputStream in = new ByteBufInputStream(content)) {
		rawResponse = objectMapper.readTree(in);
		LOG.debug("Received response {}.", rawResponse);
	} catch (JsonProcessingException je) {
		LOG.error("Response was not valid JSON.", je);
		// let's see if it was a plain-text message instead
		content.readerIndex(0);
		try (ByteBufInputStream in = new ByteBufInputStream(content)) {
			byte[] data = new byte[in.available()];
			in.readFully(data);
			String message = new String(data);
			LOG.error("Unexpected plain-text response: {}", message);
			jsonFuture.completeExceptionally(new RestClientException("Response was not valid JSON, but plain-text: " + message, je, msg.getStatus()));
		} catch (IOException e) {
			jsonFuture.completeExceptionally(new RestClientException("Response was not valid JSON, nor plain-text.", je, msg.getStatus()));
		}
		return;
	} catch (IOException ioe) {
		LOG.error("Response could not be read.", ioe);
		jsonFuture.completeExceptionally(new RestClientException("Response could not be read.", ioe, msg.getStatus()));
		return;
	}
	jsonFuture.complete(new JsonResponse(rawResponse, msg.getStatus()));
}
 
Example #7
Source File: MessageSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * De-serializes the {@link RequestFailure} sent to the
 * {@link org.apache.flink.queryablestate.network.Client} in case of
 * protocol related errors.
 * <pre>
 *  <b>The buffer is expected to be at the correct position.</b>
 * </pre>
 * @param buf	The {@link ByteBuf} containing the serialized failure message.
 * @return		The failure message.
 */
public static RequestFailure deserializeRequestFailure(final ByteBuf buf) throws IOException, ClassNotFoundException {
	long requestId = buf.readLong();

	Throwable cause;
	try (ByteBufInputStream bis = new ByteBufInputStream(buf);
			ObjectInputStream in = new ObjectInputStream(bis)) {
		cause = (Throwable) in.readObject();
	}
	return new RequestFailure(requestId, cause);
}
 
Example #8
Source File: RestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
private void readRawResponse(FullHttpResponse msg) {
	ByteBuf content = msg.content();

	JsonNode rawResponse;
	try (InputStream in = new ByteBufInputStream(content)) {
		rawResponse = objectMapper.readTree(in);
		LOG.debug("Received response {}.", rawResponse);
	} catch (JsonProcessingException je) {
		LOG.error("Response was not valid JSON.", je);
		// let's see if it was a plain-text message instead
		content.readerIndex(0);
		try (ByteBufInputStream in = new ByteBufInputStream(content)) {
			byte[] data = new byte[in.available()];
			in.readFully(data);
			String message = new String(data);
			LOG.error("Unexpected plain-text response: {}", message);
			jsonFuture.completeExceptionally(new RestClientException("Response was not valid JSON, but plain-text: " + message, je, msg.getStatus()));
		} catch (IOException e) {
			jsonFuture.completeExceptionally(new RestClientException("Response was not valid JSON, nor plain-text.", je, msg.getStatus()));
		}
		return;
	} catch (IOException ioe) {
		LOG.error("Response could not be read.", ioe);
		jsonFuture.completeExceptionally(new RestClientException("Response could not be read.", ioe, msg.getStatus()));
		return;
	}
	jsonFuture.complete(new JsonResponse(rawResponse, msg.getStatus()));
}
 
Example #9
Source File: MessageSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * De-serializes the {@link RequestFailure} sent to the
 * {@link org.apache.flink.queryablestate.network.Client} in case of
 * protocol related errors.
 * <pre>
 *  <b>The buffer is expected to be at the correct position.</b>
 * </pre>
 * @param buf	The {@link ByteBuf} containing the serialized failure message.
 * @return		The failure message.
 */
public static RequestFailure deserializeRequestFailure(final ByteBuf buf) throws IOException, ClassNotFoundException {
	long requestId = buf.readLong();

	Throwable cause;
	try (ByteBufInputStream bis = new ByteBufInputStream(buf);
			ObjectInputStream in = new ObjectInputStream(bis)) {
		cause = (Throwable) in.readObject();
	}
	return new RequestFailure(requestId, cause);
}
 
Example #10
Source File: MessageSerializer.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
/**
 * De-serializes the failure message sent to the
 * {@link org.apache.flink.queryablestate.network.Client} in case of
 * server related errors.
 * <pre>
 *  <b>The buffer is expected to be at the correct position.</b>
 * </pre>
 * @param buf	The {@link ByteBuf} containing the serialized failure message.
 * @return		The failure message.
 */
public static Throwable deserializeServerFailure(final ByteBuf buf) throws IOException, ClassNotFoundException {
	try (ByteBufInputStream bis = new ByteBufInputStream(buf);
			ObjectInputStream in = new ObjectInputStream(bis)) {
		return (Throwable) in.readObject();
	}
}
 
Example #11
Source File: MessageSerializer.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * De-serializes the failure message sent to the
 * {@link org.apache.flink.queryablestate.network.Client} in case of
 * server related errors.
 * <pre>
 *  <b>The buffer is expected to be at the correct position.</b>
 * </pre>
 * @param buf	The {@link ByteBuf} containing the serialized failure message.
 * @return		The failure message.
 */
public static Throwable deserializeServerFailure(final ByteBuf buf) throws IOException, ClassNotFoundException {
	try (ByteBufInputStream bis = new ByteBufInputStream(buf);
			ObjectInputStream in = new ObjectInputStream(bis)) {
		return (Throwable) in.readObject();
	}
}
 
Example #12
Source File: MessageSerializer.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * De-serializes the failure message sent to the
 * {@link org.apache.flink.queryablestate.network.Client} in case of
 * server related errors.
 * <pre>
 *  <b>The buffer is expected to be at the correct position.</b>
 * </pre>
 * @param buf	The {@link ByteBuf} containing the serialized failure message.
 * @return		The failure message.
 */
public static Throwable deserializeServerFailure(final ByteBuf buf) throws IOException, ClassNotFoundException {
	try (ByteBufInputStream bis = new ByteBufInputStream(buf);
			ObjectInputStream in = new ObjectInputStream(bis)) {
		return (Throwable) in.readObject();
	}
}