Example usage for java.io File getFreeSpace

List of usage examples for java.io File getFreeSpace

Introduction

In this page you can find the example usage for java.io File getFreeSpace.

Prototype

public long getFreeSpace() 

Source Link

Document

Returns the number of unallocated bytes in the partition named by this abstract path name.

Usage

From source file:de.uni_koblenz.jgralab.utilities.tgraphbrowser.TGraphBrowserServer.java

public TGraphBrowserServer(int port, String path, String maximumFileSize, String maximumWorkspaceSize)
        throws IOException {
    if (path == null) {
        throw new IllegalArgumentException("path must not be null");
    }/*from  w w w . j a  va2  s  . c o m*/
    workspace = path;
    if ((path != null) && (workspace.startsWith("\"") || workspace.startsWith("'"))) {
        workspace = workspace.substring(1, workspace.length() - 1);
    }
    StateRepository.MAXIMUM_FILE_SIZE = maximumFileSize == null ? null
            : Long.parseLong(maximumFileSize) * 1024 * 1024;
    File ws = new File(workspace);
    StateRepository.MAXIMUM_WORKSPACE_SIZE = maximumWorkspaceSize == null
            ? ws.getFreeSpace() + ws.getTotalSpace()
            : Long.parseLong(maximumWorkspaceSize) * 1024 * 1024;
    _serverSocket = new ServerSocket(port);
}

From source file:org.wso2.emm.agent.api.DeviceState.java

/**
 * Returns the available external memory size.
 *
 * @return - Available external memory size.
 *///from w w w  .j  a v a2s  .co m
public double getAvailableExternalMemorySize() {
    long freeBytesExternal = 0;
    if (externalMemoryAvailable()) {
        for (File dir : externalStorageDirectoryList) {
            if (dir != null && !dir.getAbsolutePath().contains(INTERNAL_STORAGE_PATH)) {
                freeBytesExternal += dir.getFreeSpace();
            }
        }
        return formatSizeInGb(freeBytesExternal);
    } else {
        return MEMORY_NOT_AVAILABLE;
    }
}

From source file:org.wso2.carbon.core.bootup.validator.SystemValidator.java

/**
 * @return maximum free disk space in the filesystem
 *//*from  ww w.ja  v a  2 s  .co m*/
private long getMaxFreeDiskSpace() {
    // list of all filesystem roots of this system
    long maxFreeSpace = 0;
    File[] roots = File.listRoots();
    for (File disk : roots) {
        long diskFreeSpace = disk.getFreeSpace() / MB_BASE;
        if (disk.isDirectory() && (diskFreeSpace > maxFreeSpace)) {
            maxFreeSpace = diskFreeSpace;
        }
    }
    return maxFreeSpace;
}

From source file:org.chromium.ChromeSystemStorage.java

private JSONObject buildAvailableCapacityInfo(String id, File directory) throws JSONException {
    JSONObject storageUnit = new JSONObject();

    storageUnit.put("id", id);
    storageUnit.put("availableCapacity", directory.getFreeSpace());

    return storageUnit;
}

From source file:fr.sedona.volley.manager.HttpImageLoader.java

@SuppressLint("NewApi")
private long getDiskCacheSpace(Context context) {
    String cachePath = context.getCacheDir().getPath();
    File diskCacheDir = new File(cachePath);

    if (Build.VERSION.SDK_INT >= 9) {
        return Math.min(diskCacheDir.getFreeSpace() - (1024 * 1024 * 30), (long) 1024 * 1024 * 20);
    }//from   www . j a  v a2s . c  om
    StatFs statFs = new StatFs(diskCacheDir.getAbsolutePath());
    return (long) Math.min(statFs.getAvailableBlocks() * (long) statFs.getBlockSize() - (1024 * 1024 * 30),
            (long) 1024 * 1024 * 20);
}

From source file:com.android.purenexussettings.BuildPropFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mCoordLayout = (CoordinatorLayout) view.findViewById(R.id.buildpropcoord);
    recyclerView = (RecyclerView) view.findViewById(R.id.recyclerList);

    // Attempt to flag instances where writing to build.prop
    // is not possible due to no space
    String filepath = "/system";
    File file = new File(filepath);

    long freeSpace = file.getFreeSpace();
    //long useSpace = file.getUsableSpace();

    if (file.getFreeSpace() == 0) {
        mHasRoom = false;//from w w w.  j  av a  2  s .  co m
        Snackbar.make(mCoordLayout, getString(R.string.no_room_error), Snackbar.LENGTH_SHORT).show();
    } else {
        mHasRoom = true;
    }

    (new LoadProp()).setInits(getActivity(), mCoordLayout, recyclerView, false).execute();

    FloatingActionButton fabAdd = (FloatingActionButton) view.findViewById(R.id.fab);
    fabAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mHasRoom && TinkerActivity.isRoot) {
                ((TinkerActivity) getActivity()).displayEditProp(null, null);
            } else {
                Snackbar.make(mCoordLayout,
                        (mHasRoom ? "" : getString(R.string.no_room_error))
                                + (!mHasRoom && !TinkerActivity.isRoot ? "\n" : "")
                                + (TinkerActivity.isRoot ? "" : getString(R.string.no_root_error)),
                        Snackbar.LENGTH_SHORT).show();
            }
        }
    });
}

From source file:tajo.master.MockupWorker.java

@Override
public ServerStatusProto getServerStatus(PrimitiveProtos.NullProto request) {
    // serverStatus builder
    ServerStatusProto.Builder serverStatus = ServerStatusProto.newBuilder();
    // TODO: compute the available number of task slots
    serverStatus.setAvailableTaskSlotNum(taskQueue.size());

    // system(CPU, memory) status builder
    ServerStatusProto.System.Builder systemStatus = ServerStatusProto.System.newBuilder();

    systemStatus.setAvailableProcessors(Runtime.getRuntime().availableProcessors());
    systemStatus.setFreeMemory(Runtime.getRuntime().freeMemory());
    systemStatus.setMaxMemory(Runtime.getRuntime().maxMemory());
    systemStatus.setTotalMemory(Runtime.getRuntime().totalMemory());

    serverStatus.setSystem(systemStatus);

    // disk status builder
    File[] roots = File.listRoots();
    for (File root : roots) {
        ServerStatusProto.Disk.Builder diskStatus = ServerStatusProto.Disk.newBuilder();

        diskStatus.setAbsolutePath(root.getAbsolutePath());
        diskStatus.setTotalSpace(root.getTotalSpace());
        diskStatus.setFreeSpace(root.getFreeSpace());
        diskStatus.setUsableSpace(root.getUsableSpace());

        serverStatus.addDisk(diskStatus);
    }//  w  ww. jav a2s . c  om
    return serverStatus.build();
}

From source file:com.comcast.cdn.traffic_control.traffic_router.neustar.data.NeustarDatabaseUpdater.java

public boolean enoughFreeSpace(File destination, HttpResponse response, String request) {
    Header contentLengthHeader = response.getFirstHeader("Content-Length");

    if (contentLengthHeader == null) {
        LOGGER.warn("Unable to determine size of data from " + request);
        return true;
    }//ww  w  . j av  a2  s  .co m

    long contentLength = parseLong(contentLengthHeader.getValue());
    long freespace = destination.getFreeSpace();

    if (freespace < contentLength) {
        LOGGER.error("Not enough space in " + destination + " to save " + request + "(Free: " + freespace
                + ", Need: " + contentLength);
        return false;
    }

    return true;
}

From source file:org.disrupted.rumble.database.statistics.StatisticManager.java

public JSONObject generateStatJSON() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("rumble_version", RumbleApplication.BUILD_VERSION);
    json.put("android_build", Integer.toString(Build.VERSION.SDK_INT));
    json.put("phone_model", Build.MODEL);
    json.put("anonymous_id", RumblePreferences.getAnonymousID(RumbleApplication.getContext()));
    json.put("timestamp", System.currentTimeMillis());

    JSONArray resultSet;/*  ww  w.j a  va2 s .  c  om*/
    resultSet = DatabaseFactory.getStatChannelDatabase(RumbleApplication.getContext()).getJSON();
    json.put("channels", resultSet);
    resultSet = DatabaseFactory.getStatLinkLayerDatabase(RumbleApplication.getContext()).getJSON();
    json.put("link-layer", resultSet);
    resultSet = DatabaseFactory.getStatReachabilityDatabase(RumbleApplication.getContext()).getJSON();
    json.put("reachability", resultSet);
    resultSet = DatabaseFactory.getStatMessageDatabase(RumbleApplication.getContext()).getJSON();
    json.put("messages", resultSet);

    resultSet = new JSONArray();
    resultSet.put((new JSONObject()).put(
            DatabaseFactory.getPushStatusDatabase(RumbleApplication.getContext()).getTableName(),
            DatabaseFactory.getPushStatusDatabase(RumbleApplication.getContext()).getCount()));
    resultSet.put((new JSONObject()).put(
            DatabaseFactory.getChatMessageDatabase(RumbleApplication.getContext()).getTableName(),
            DatabaseFactory.getChatMessageDatabase(RumbleApplication.getContext()).getCount()));
    resultSet.put((new JSONObject()).put(
            DatabaseFactory.getGroupDatabase(RumbleApplication.getContext()).getTableName(),
            DatabaseFactory.getGroupDatabase(RumbleApplication.getContext()).getCount()));
    resultSet.put((new JSONObject()).put(
            DatabaseFactory.getContactDatabase(RumbleApplication.getContext()).getTableName(),
            DatabaseFactory.getContactDatabase(RumbleApplication.getContext()).getCount()));
    resultSet.put((new JSONObject()).put(
            DatabaseFactory.getHashtagDatabase(RumbleApplication.getContext()).getTableName(),
            DatabaseFactory.getHashtagDatabase(RumbleApplication.getContext()).getCount()));

    long fileSize = 0;
    long freespace = 0;
    try {
        File dir = FileUtil.getReadableAlbumStorageDir();
        if (dir != null) {
            File files[] = dir.listFiles();
            if (files != null) {
                for (File file : files) {
                    fileSize += file.length();
                }
            }
            freespace = dir.getFreeSpace();
        }
    } catch (IOException ie) {
    }
    resultSet.put((new JSONObject()).put(KEY_FREE_SPACE, freespace));
    resultSet.put((new JSONObject()).put(KEY_FILE_SIZE, fileSize));
    json.put("db", resultSet);

    return json;
}

From source file:tajo.worker.Worker.java

@Override
public ServerStatusProto getServerStatus(NullProto request) {
    // serverStatus builder
    ServerStatusProto.Builder serverStatus = ServerStatusProto.newBuilder();
    // TODO: compute the available number of task slots
    serverStatus.setAvailableTaskSlotNum(MAX_TASK_NUM - tasks.size());

    // system(CPU, memory) status builder
    ServerStatusProto.System.Builder systemStatus = ServerStatusProto.System.newBuilder();

    systemStatus.setAvailableProcessors(Runtime.getRuntime().availableProcessors());
    systemStatus.setFreeMemory(Runtime.getRuntime().freeMemory());
    systemStatus.setMaxMemory(Runtime.getRuntime().maxMemory());
    systemStatus.setTotalMemory(Runtime.getRuntime().totalMemory());

    serverStatus.setSystem(systemStatus);

    // disk status builder
    File[] roots = File.listRoots();
    for (File root : roots) {
        ServerStatusProto.Disk.Builder diskStatus = ServerStatusProto.Disk.newBuilder();

        diskStatus.setAbsolutePath(root.getAbsolutePath());
        diskStatus.setTotalSpace(root.getTotalSpace());
        diskStatus.setFreeSpace(root.getFreeSpace());
        diskStatus.setUsableSpace(root.getUsableSpace());

        serverStatus.addDisk(diskStatus);
    }//from  ww w  .  ja va  2 s . c om
    return serverStatus.build();
}