001 /* 002 * Copyright (c) 2011, Cloudera, Inc. All Rights Reserved. 003 * 004 * Cloudera, Inc. licenses this file to you under the Apache License, 005 * Version 2.0 (the "License"). You may not use this file except in 006 * compliance with the License. You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * This software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 011 * CONDITIONS OF ANY KIND, either express or implied. See the License for 012 * the specific language governing permissions and limitations under the 013 * License. 014 */ 015 package com.cloudera.lib.wsrs; 016 017 import com.cloudera.lib.io.IOUtils; 018 019 import javax.ws.rs.core.StreamingOutput; 020 import java.io.IOException; 021 import java.io.InputStream; 022 import java.io.OutputStream; 023 024 public class InputStreamEntity implements StreamingOutput { 025 private InputStream is; 026 private long offset; 027 private long len; 028 029 public InputStreamEntity(InputStream is, long offset, long len) { 030 this.is = is; 031 this.offset = offset; 032 this.len = len; 033 } 034 035 public InputStreamEntity(InputStream is) { 036 this(is, 0, -1); 037 } 038 039 @Override 040 public void write(OutputStream os) throws IOException { 041 IOUtils.copy(is, os, offset, len); 042 } 043 }