001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hdfs.server.datanode.fsdataset; 019 020import java.io.Closeable; 021import java.io.InputStream; 022 023import org.apache.hadoop.io.IOUtils; 024 025/** 026 * Contains the input streams for the data and checksum of a replica. 027 */ 028public class ReplicaInputStreams implements Closeable { 029 private final InputStream dataIn; 030 private final InputStream checksumIn; 031 private final FsVolumeReference volumeRef; 032 033 /** Create an object with a data input stream and a checksum input stream. */ 034 public ReplicaInputStreams(InputStream dataStream, InputStream checksumStream, 035 FsVolumeReference volumeRef) { 036 this.volumeRef = volumeRef; 037 this.dataIn = dataStream; 038 this.checksumIn = checksumStream; 039 } 040 041 /** @return the data input stream. */ 042 public InputStream getDataIn() { 043 return dataIn; 044 } 045 046 /** @return the checksum input stream. */ 047 public InputStream getChecksumIn() { 048 return checksumIn; 049 } 050 051 @Override 052 public void close() { 053 IOUtils.closeStream(dataIn); 054 IOUtils.closeStream(checksumIn); 055 IOUtils.cleanup(null, volumeRef); 056 } 057}