001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.vfs2.provider.gzip; 018 019import java.io.InputStream; 020import java.io.OutputStream; 021import java.util.zip.GZIPInputStream; 022import java.util.zip.GZIPOutputStream; 023 024import org.apache.commons.vfs2.FileObject; 025import org.apache.commons.vfs2.provider.AbstractFileName; 026import org.apache.commons.vfs2.provider.compressed.CompressedFileFileObject; 027import org.apache.commons.vfs2.provider.compressed.CompressedFileFileSystem; 028 029/** 030 * the gzip file. 031 */ 032public class GzipFileObject extends CompressedFileFileObject<GzipFileSystem> { 033 /** 034 * Deprecated since 2.1. 035 * 036 * @deprecated Use {@link #GzipFileObject(AbstractFileName, FileObject, GzipFileSystem)} instead. 037 */ 038 @Deprecated 039 protected GzipFileObject(final AbstractFileName name, final FileObject container, 040 final CompressedFileFileSystem fs) { 041 super(name, container, cast(fs)); 042 } 043 044 protected GzipFileObject(final AbstractFileName name, final FileObject container, final GzipFileSystem fs) { 045 super(name, container, fs); 046 } 047 048 @Override 049 protected InputStream doGetInputStream() throws Exception { 050 final InputStream is = getContainer().getContent().getInputStream(); 051 return new GZIPInputStream(is); 052 } 053 054 @Override 055 protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception { 056 final OutputStream os = getContainer().getContent().getOutputStream(false); 057 return new GZIPOutputStream(os); 058 } 059 060 private static GzipFileSystem cast(final CompressedFileFileSystem fs) { 061 if (fs instanceof GzipFileSystem) { 062 return (GzipFileSystem) fs; 063 } 064 throw new IllegalArgumentException("GzipFileObject expects an instance of GzipFileSystem"); 065 } 066}