001/* 002 * Copyright 2011-2012 Stephen Connolly. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.jszip.pseudo.io; 018 019import java.io.File; 020import java.io.FileInputStream; 021import java.io.FileOutputStream; 022import java.io.IOException; 023import java.io.InputStream; 024import java.io.OutputStream; 025 026public class FilePseudoFile extends PseudoFile { 027 028 private final File delegate; 029 030 public FilePseudoFile(PseudoFile parent, File delegate) { 031 super(parent); 032 this.delegate = delegate; 033 } 034 035 /** 036 * {@inheritDoc} 037 */ 038 public boolean canRead() { 039 return delegate.canRead(); 040 } 041 042 /** 043 * {@inheritDoc} 044 */ 045 public boolean canWrite() { 046 return delegate.canWrite(); 047 } 048 049 /** 050 * {@inheritDoc} 051 */ 052 public boolean createNewFile() throws IOException { 053 return delegate.createNewFile(); 054 } 055 056 /** 057 * {@inheritDoc} 058 */ 059 public boolean delete() { 060 return delegate.delete(); 061 } 062 063 /** 064 * {@inheritDoc} 065 */ 066 public boolean renameTo(PseudoFile dest) { 067 while (dest instanceof ProxyPseudoFile) { 068 dest = ((ProxyPseudoFile) dest).$unwrap(); 069 } 070 if (dest instanceof FilePseudoFile) { 071 return delegate.renameTo(FilePseudoFile.class.cast(dest).delegate); 072 } 073 if (dest.getParentFile().equals(getParentFile())) { 074 return delegate.renameTo(new File(delegate.getParent(), dest.getName())); 075 } 076 return false; 077 } 078 079 /** 080 * {@inheritDoc} 081 */ 082 public boolean exists() { 083 return delegate.exists(); 084 } 085 086 /** 087 * {@inheritDoc} 088 */ 089 public boolean isDirectory() { 090 return delegate.isDirectory(); 091 } 092 093 /** 094 * {@inheritDoc} 095 */ 096 public long lastModified() { 097 return delegate.lastModified(); 098 } 099 100 /** 101 * {@inheritDoc} 102 */ 103 public String getName() { 104 return delegate.getName(); 105 } 106 107 /** 108 * {@inheritDoc} 109 */ 110 public boolean setLastModified(long time) { 111 return delegate.setLastModified(time); 112 } 113 114 /** 115 * {@inheritDoc} 116 */ 117 InputStream $newInputStream() throws IOException { 118 return new FileInputStream(delegate); 119 } 120 121 /** 122 * {@inheritDoc} 123 */ 124 OutputStream $newOutputStream() throws IOException { 125 return new FileOutputStream(delegate); 126 } 127 128 /** 129 * {@inheritDoc} 130 */ 131 OutputStream $newOutputStream(boolean append) throws IOException { 132 return new FileOutputStream(delegate, append); 133 } 134 135 /** 136 * {@inheritDoc} 137 */ 138 public boolean isFile() { 139 return delegate.isFile(); 140 } 141 142 /** 143 * {@inheritDoc} 144 */ 145 public boolean mkdir() { 146 return delegate.mkdir(); 147 } 148 149 /** 150 * {@inheritDoc} 151 */ 152 public void deleteOnExit() { 153 delegate.deleteOnExit(); 154 } 155 156 /** 157 * {@inheritDoc} 158 */ 159 public boolean mkdirs() { 160 return delegate.mkdirs(); 161 } 162 163 /** 164 * {@inheritDoc} 165 */ 166 public boolean isHidden() { 167 return delegate.isHidden(); 168 } 169 170 /** 171 * {@inheritDoc} 172 */ 173 public long length() { 174 return delegate.length(); 175 } 176 177}