当前位置: 首页>>代码示例>>Java>>正文


Java Os.stat方法代码示例

本文整理汇总了Java中android.system.Os.stat方法的典型用法代码示例。如果您正苦于以下问题:Java Os.stat方法的具体用法?Java Os.stat怎么用?Java Os.stat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.system.Os的用法示例。


在下文中一共展示了Os.stat方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: calculateSize

import android.system.Os; //导入方法依赖的package包/类
/**
 * Calculate size of the entry reading directory tree
 * @param file is file corresponding to this entry
 * @return size of entry in blocks
 */
private final long calculateSize(LegacyFile file) {
  if (file.isLink()) return 0;

  if (file.isFile()) {
    try {
      StructStat res = Os.stat(file.getCannonicalPath());
      return res.st_blocks;
    } catch (ErrnoException|IOException e) {
      return 0;
    }
  }

  LegacyFile[] list = null;
  try {
    list = file.listFiles();
  } catch (SecurityException io) {
    Log.e("diskusage", "list files", io);
  }
  if (list == null) return 0;
  long size = 1;

  for (int i = 0; i < list.length; i++)
    size += calculateSize(list[i]);
  return size;
}
 
开发者ID:IvanVolosyuk,项目名称:diskusage,代码行数:31,代码来源:Scanner.java

示例2: scan

import android.system.Os; //导入方法依赖的package包/类
public FileSystemEntry scan(LegacyFile file) throws IOException {
    long st_blocks;
    try {
      StructStat stat = Os.stat(file.getCannonicalPath());
      dev = stat.st_dev;
      st_blocks = stat.st_blocks;
    } catch (ErrnoException e) {
      throw new IOException("Failed to find root folder", e);
    }
    scanDirectory(null, file, 0, st_blocks / blockSizeIn512Bytes);
    int extraHeap = 0;

    // Restoring blocks
    for (SmallList list : smallLists) {
//      print("restored", list);

      FileSystemEntry[] oldChildren = list.parent.children;
      FileSystemEntry[] addChildren = list.children;
      FileSystemEntry[] newChildren =
        new FileSystemEntry[oldChildren.length - 1 + addChildren.length];
      System.arraycopy(addChildren, 0, newChildren, 0, addChildren.length);
      for(int pos = addChildren.length, i = 0; i < oldChildren.length; i++) {
        FileSystemEntry c = oldChildren[i];
        if (! (c instanceof FileSystemEntrySmall)) {
          newChildren[pos++] = c;
        }
      }
      java.util.Arrays.sort(newChildren, FileSystemEntry.COMPARE);
      list.parent.children = newChildren;
      extraHeap += list.heapSize;
    }
    Log.d("diskusage", "allocated " + extraHeap + " B of extra heap");
    Log.d("diskusage", "allocated " + (extraHeap + createdNodeSize) + " B total");
    return createdNode;
  }
 
开发者ID:IvanVolosyuk,项目名称:diskusage,代码行数:36,代码来源:Scanner.java

示例3: smartLength

import android.system.Os; //导入方法依赖的package包/类
@TargetApi(LOLLIPOP)
@SneakyThrows
private static long smartLength(File file) {
    long length = file.length();

    StructStat stat = Os.stat(file.getAbsolutePath());
    long blockBasedLength = stat.st_blksize * stat.st_blocks;
    return min(length, blockBasedLength);
}
 
开发者ID:FlightOfStairs,项目名称:ADirStat,代码行数:10,代码来源:Scanner.java

示例4: checkStoragePermission

import android.system.Os; //导入方法依赖的package包/类
static boolean checkStoragePermission(Fragment fragment) {
    if (Build.VERSION.SDK_INT < 23) {
        // runtime permissions not supported
        return false;
    }

    final Context context = fragment.getActivity();
    final String prefName = context.getString(R.string.download_dir_pref);
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    final String dDir = prefs.getString(prefName, "");

    try {
        if (Build.VERSION.SDK_INT >= 24) {
            if (!TextUtils.isEmpty(dDir)) {
                final File file = new File(dDir);
                final StorageManager sm = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
                final StorageVolume sv = sm.getStorageVolume(file);
                if (sv == null || !Environment.MEDIA_MOUNTED.equals(sv.getState())) {
                    return false;
                }
            }
        } else {
            // use old-fashioned stat() check
            try {
                final File primaryStorage = Environment.getExternalStorageDirectory();
                if (primaryStorage != null) {
                    final StructStat dirStat = Os.stat(dDir);
                    final StructStat primaryStat = Os.stat(primaryStorage.getAbsolutePath());
                    if (dirStat.st_dev != primaryStat.st_dev) {
                        // the directory is not on primary external storage, bail
                        return false;
                    }
                }
            } catch (Exception ignored) {
            }
        }

        if (context.checkSelfPermission(WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            fragment.requestPermissions(new String[] { WRITE_EXTERNAL_STORAGE }, R.id.req_file_permission);
            return true;
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
    }

    return false;
}
 
开发者ID:chdir,项目名称:aria2-android,代码行数:48,代码来源:PermissionHelper.java


注:本文中的android.system.Os.stat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。