1 package org.robolectric.shadows; 2 3 import android.os.Build; 4 import android.system.ErrnoException; 5 import android.system.StructStat; 6 import java.io.File; 7 import java.io.FileDescriptor; 8 import org.robolectric.RuntimeEnvironment; 9 import org.robolectric.annotation.Implementation; 10 import org.robolectric.annotation.Implements; 11 import org.robolectric.util.ReflectionHelpers; 12 13 @Implements(className = "libcore.io.Posix", maxSdk = Build.VERSION_CODES.N_MR1, isInAndroidSdk = false) 14 public class ShadowPosix { 15 @Implementation 16 public static void mkdir(String path, int mode) throws ErrnoException { 17 new File(path).mkdirs(); 18 } 19 20 @Implementation 21 public static Object stat(String path) throws ErrnoException { 22 if (RuntimeEnvironment.getApiLevel() >= Build.VERSION_CODES.LOLLIPOP) { 23 return new StructStat(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 24 } else { 25 return ReflectionHelpers.newInstance(ReflectionHelpers.loadClass(ShadowPosix.class.getClassLoader(), "libcore.io.StructStat")); 26 } 27 } 28 29 @Implementation 30 protected static Object fstat(FileDescriptor fd) throws ErrnoException { 31 return stat(null); 32 } 33 } 34