1 package org.robolectric.shadows; 2 3 import android.content.res.AssetManager.AssetInputStream; 4 import java.io.IOException; 5 import java.io.InputStream; 6 import org.robolectric.annotation.Implementation; 7 import org.robolectric.annotation.Implements; 8 import org.robolectric.annotation.RealObject; 9 import org.robolectric.shadow.api.Shadow; 10 import org.robolectric.shadows.ShadowAssetInputStream.Picker; 11 12 @SuppressWarnings("UnusedDeclaration") 13 @Implements(value = AssetInputStream.class, shadowPicker = Picker.class) 14 public class ShadowLegacyAssetInputStream extends ShadowAssetInputStream { 15 16 @RealObject 17 private AssetInputStream realObject; 18 19 private InputStream delegate; 20 private boolean ninePatch; 21 22 @Override getDelegate()23 InputStream getDelegate() { 24 return delegate; 25 } 26 setDelegate(InputStream delegate)27 void setDelegate(InputStream delegate) { 28 this.delegate = delegate; 29 } 30 31 @Override isNinePatch()32 boolean isNinePatch() { 33 return ninePatch; 34 } 35 setNinePatch(boolean ninePatch)36 void setNinePatch(boolean ninePatch) { 37 this.ninePatch = ninePatch; 38 } 39 40 @Implementation read()41 protected int read() throws IOException { 42 return stream().read(); 43 } 44 45 @Implementation read(byte[] b)46 protected int read(byte[] b) throws IOException { 47 return stream().read(b); 48 } 49 50 @Implementation read(byte[] b, int off, int len)51 protected int read(byte[] b, int off, int len) throws IOException { 52 return stream().read(b, off, len); 53 } 54 55 @Implementation skip(long n)56 protected long skip(long n) throws IOException { 57 return stream().skip(n); 58 } 59 60 @Implementation available()61 protected int available() throws IOException { 62 return stream().available(); 63 } 64 65 @Implementation close()66 protected void close() throws IOException { 67 stream().close(); 68 } 69 70 @Implementation mark(int readlimit)71 protected void mark(int readlimit) { 72 stream().mark(readlimit); 73 } 74 75 @Implementation reset()76 protected void reset() throws IOException { 77 stream().reset(); 78 } 79 80 @Implementation markSupported()81 protected boolean markSupported() { 82 return stream().markSupported(); 83 } 84 stream()85 private InputStream stream() { 86 return delegate == null ? Shadow.directlyOn(realObject, AssetInputStream.class) : delegate; 87 } 88 } 89