• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 The gRPC Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.grpc;
18 
19 import java.io.InputStream;
20 
21 /**
22  * An extension of {@link InputStream} that allows the underlying data source to be detached and
23  * transferred to a new instance of the same kind. The detached InputStream takes over the
24  * ownership of the underlying data source. That's said, the detached InputStream is responsible
25  * for releasing its resources after use. The detached InputStream preserves internal states of
26  * the underlying data source. Data can be consumed through the detached InputStream as if being
27  * continually consumed through the original instance. The original instance discards internal
28  * states of detached data source and is no longer consumable as if the data source is exhausted.
29  *
30  * <p>A normal usage of this API is to extend the lifetime of the data source owned by the
31  * original instance for doing extra processing before releasing it. For example, when combined
32  * with {@link HasByteBuffer}, a custom {@link io.grpc.MethodDescriptor.Marshaller} can take
33  * over the ownership of buffers containing inbound data and perform delayed deserialization.
34  */
35 public interface Detachable {
36 
37   /**
38    * Detaches the underlying data source from this instance and transfers to an {@link
39    * InputStream}. Detaching data from an already-detached instance gives an InputStream with
40    * zero bytes of data.
41    *
42    */
detach()43   InputStream detach();
44 }
45