Example usage for java.io File getTotalSpace

List of usage examples for java.io File getTotalSpace

Introduction

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

Prototype

public long getTotalSpace() 

Source Link

Document

Returns the size of the partition named by this abstract pathname.

Usage

From source file:br.com.brolam.cloudvision.ui.helpers.ImagesHelper.java

/**
 * Analisar e validar uma imagem de background para um Note Vision.
 * @param noteVisionKey/*from   w  w w  .ja  va 2s.  c  o  m*/
 * @return verdadeiro se a imagem for vlida.
 */
private boolean parseImageNoteVisionBackground(String noteVisionKey) {
    Uri imageUri = getImageUriFile(noteVisionKey);
    File imageFile = new File(imageUri.getPath());
    if (imageFile.exists()) {
        //Reduzir o tamanho de imagens acima de 1MB.
        if (imageFile.getTotalSpace() > 1048576) {
            //Tentar reduzir o tamanho da imagem.
            try {
                resizeImage(imageUri.getPath(), noteVisionBackgroundWidth, noteVisionBackgroundHeight);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else if (imageFile.getTotalSpace() == 0) {
            //Excluir a imagem se a mesma no for vlida.
            imageFile.delete();
            return false;
        }
        return true;
    }
    ;
    return false;
}

From source file:org.apache.hadoop.yarn.server.nodemanager.DirectoryCollection.java

private boolean isDiskUsageOverPercentageLimit(File dir, float diskUtilizationPercentageCutoff) {
    float freePercentage = 100 * (dir.getUsableSpace() / (float) dir.getTotalSpace());
    float usedPercentage = 100.0F - freePercentage;
    return (usedPercentage > diskUtilizationPercentageCutoff || usedPercentage >= 100.0F);
}

From source file:org.apache.hadoop.yarn.server.nodemanager.DirectoryCollection.java

private void setGoodDirsDiskUtilizationPercentage() {

    long totalSpace = 0;
    long usableSpace = 0;

    for (String dir : localDirs) {
        File f = new File(dir);
        if (!f.isDirectory()) {
            continue;
        }/*  w ww .j a v a  2 s. c o  m*/
        totalSpace += f.getTotalSpace();
        usableSpace += f.getUsableSpace();
    }
    if (totalSpace != 0) {
        long tmp = ((totalSpace - usableSpace) * 100) / totalSpace;
        if (Integer.MIN_VALUE < tmp && Integer.MAX_VALUE > tmp) {
            goodDirsDiskUtilizationPercentage = (int) tmp;
        }
    } else {
        // got no good dirs
        goodDirsDiskUtilizationPercentage = 0;
    }
}

From source file:org.chromium.ChromeSystemStorage.java

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

    storageUnit.put("id", id);
    storageUnit.put("name", name);
    storageUnit.put("type", type);
    storageUnit.put("capacity", directory.getTotalSpace());

    return storageUnit;
}

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  www .ja va2 s .  co  m
    return serverStatus.build();
}

From source file:com.aliyun.odps.mapred.local.LocalTaskContext.java

@Override
public Iterator<Record> readResourceTable(String tbl) throws IOException {
    if (StringUtils.isEmpty(tbl)) {
        throw new IOException("Table resouce name is empty or null");
    }//from w w w  .  ja  v a  2  s. c o  m

    if (!jobDirecotry.hasResource(tbl)) {
        String project = SessionState.get().getOdps().getDefaultProject();
        try {
            WareHouse.getInstance().copyResource(project, tbl, jobDirecotry.getResourceDir(),
                    WareHouse.getInstance().getLimitDownloadRecordCount(),
                    WareHouse.getInstance().getInputColumnSeperator());
        } catch (OdpsException e) {
        }
    }

    File dir = new File(jobDirecotry.getResourceDir(), tbl);
    LOG.info("Reading resource table from " + dir);
    final List<File> datafiles = new ArrayList<File>();

    LocalRunUtils.listAllDataFiles(dir, datafiles);

    final TableMeta tableMeta = SchemaUtils.readSchema(dir);

    return new Iterator<Record>() {
        RecordReader reader;
        Record current;
        boolean fetched;

        @Override
        public boolean hasNext() {
            if (fetched) {
                return current != null;
            }
            // Fetch new one
            try {
                fetch();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return current != null;

        }

        private void fetch() throws IOException {

            // first time
            if (reader == null) {
                if (datafiles.isEmpty()) {
                    current = null;
                    fetched = true;
                    return;
                }

                File f = datafiles.remove(0);
                reader = new CSVRecordReader(new FileSplit(f, tableMeta.getCols(), 0, f.getTotalSpace()),
                        tableMeta, LocalJobRunner.EMPTY_COUNTER, LocalJobRunner.EMPTY_COUNTER, counters,
                        WareHouse.getInstance().getInputColumnSeperator());
                current = reader.read();
                fetched = true;
                return;
            }

            current = reader.read();
            if (current == null && !datafiles.isEmpty()) {
                File f = datafiles.remove(0);
                reader = new CSVRecordReader(new FileSplit(f, tableMeta.getCols(), 0, f.getTotalSpace()),
                        tableMeta, LocalJobRunner.EMPTY_COUNTER, LocalJobRunner.EMPTY_COUNTER, counters,
                        WareHouse.getInstance().getInputColumnSeperator());
                current = reader.read();
                fetched = true;
                return;
            }

            fetched = true;
        }

        @Override
        public Record next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            fetched = false;
            return current;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

    };
}

From source file:org.apache.flink.runtime.taskmanager.TaskManager.java

/**
 * Checks, whether the given strings describe existing directories that are writable. If that is not
 * the case, an exception is raised./*from   www.  j a v  a  2  s. c  o m*/
 * 
 * @param tempDirs An array of strings which are checked to be paths to writable directories.
 * @throws Exception Thrown, if any of the mentioned checks fails.
 */
private static final void checkTempDirs(final String[] tempDirs) throws Exception {
    for (int i = 0; i < tempDirs.length; ++i) {
        final String dir = checkNotNull(tempDirs[i], "Temporary file directory #" + (i + 1) + " is null.");

        final File f = new File(dir);

        checkArgument(f.exists(), "Temporary file directory '" + f.getAbsolutePath() + "' does not exist.");
        checkArgument(f.isDirectory(),
                "Temporary file directory '" + f.getAbsolutePath() + "' is not a directory.");
        checkArgument(f.canWrite(), "Temporary file directory '" + f.getAbsolutePath() + "' is not writable.");

        if (LOG.isInfoEnabled()) {
            long totalSpaceGb = f.getTotalSpace() >> 30;
            long usableSpaceGb = f.getUsableSpace() >> 30;
            double usablePercentage = ((double) usableSpaceGb) / totalSpaceGb * 100;

            LOG.info(String.format("Temporary file directory '%s': total %d GB, usable %d GB [%.2f%% usable]",
                    f.getAbsolutePath(), totalSpaceGb, usableSpaceGb, usablePercentage));
        }
    }
}

From source file:UploadTest.java

@Test
public void appache_test() throws ClientProtocolException, IOException {

    String user = "edoweb-admin";
    String password = "admin";
    String encoding = Base64.encodeBase64String((user + ":" + password).getBytes());
    System.out.println(encoding);
    CredentialsProvider provider = new BasicCredentialsProvider();
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, password);
    provider.setCredentials(AuthScope.ANY, credentials);
    URL myurl = new URL("http://localhost:9000/resource/frl:6376984/data");

    // ----------------------------------------------------------------------------

    String boundary = "==" + System.currentTimeMillis() + "===";
    String filePath = "/home/raul/test/frl%3A6376982/123.txt";
    File file = new File(filePath);
    String fileLength = Long.toString(file.getTotalSpace());
    HttpEntity entity = MultipartEntityBuilder.create().addTextBody("data", boundary)
            .addBinaryBody("data", file, ContentType.create("application/pdf"), "6376986.pdf").build();
    HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();

    HttpPut put = new HttpPut(myurl.toString());
    // put.setHeader("Authorization", "Basic " + encoding);
    // put.setHeader("Accept", "*/*");
    // put.setHeader("Content-Length", fileLength);
    put.setEntity(entity);//from   w  w  w . j  a v a2s.  co m
    HttpResponse response = client.execute(put);
    int statusCode = response.getStatusLine().getStatusCode();
    System.out.println(statusCode);
    Assert.assertEquals(statusCode, HttpStatus.SC_OK);
}

From source file:org.opencastproject.workingfilerepository.impl.WorkingFileRepositoryImpl.java

/**
 * {@inheritDoc}//from www .j  a  v  a2 s.  com
 * 
 * @see org.opencastproject.workingfilerepository.api.WorkingFileRepository#getTotalSpace()
 */
public Option<Long> getTotalSpace() {
    File f = new File(rootDirectory);
    return Option.some(f.getTotalSpace());
}

From source file:san.FileSystemImpl.java

/**
* getTotalSpace()//from   ww w .  j ava2s .  co  m
* @param dirPath - directory path
* @param path - path
* @throws - SanException
* @returns - Returns the size of the partition named by this 
*            abstract path name
*/
public long getTotalSpace(String dirPath, String path) throws SanException {

    if (RegexStrUtil.isNull(dirPath) || RegexStrUtil.isNull(path)) {
        throw new SanException("getTotalSpace(), dirPath or path is null");
    }

    File dir = getDir(dirPath, path);
    if (dir == null) {
        throw new SanException("getTotalSpace() " + path + dirPath);
    }

    try {
        if (dir.exists()) {
            long totalSpace = dir.getTotalSpace();
            logger.info("totalSpace = " + totalSpace);
            return dir.getTotalSpace();
        } else {
            return 0;
        }
    } catch (Exception e) {
        throw new SanException("error in dir.getTotalSpace()" + e.getMessage(), e);
    }
}