001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.fs;
019
020import java.io.DataInput;
021import java.io.DataOutput;
022import java.io.IOException;
023
024import org.apache.hadoop.classification.InterfaceAudience;
025import org.apache.hadoop.classification.InterfaceStability;
026import org.apache.hadoop.io.Writable;
027
028/** This class is used to represent the capacity, free and used space on a
029  * {@link FileSystem}.
030  */
031@InterfaceAudience.Public
032@InterfaceStability.Stable
033public class FsStatus implements Writable {
034  private long capacity;
035  private long used;
036  private long remaining;
037
038  /** Construct a FsStatus object, using the specified statistics */
039  public FsStatus(long capacity, long used, long remaining) {
040    this.capacity = capacity;
041    this.used = used;
042    this.remaining = remaining;
043  }
044
045  /** Return the capacity in bytes of the file system */
046  public long getCapacity() {
047    return capacity;
048  }
049
050  /** Return the number of bytes used on the file system */
051  public long getUsed() {
052    return used;
053  }
054
055  /** Return the number of remaining bytes on the file system */
056  public long getRemaining() {
057    return remaining;
058  }
059
060  //////////////////////////////////////////////////
061  // Writable
062  //////////////////////////////////////////////////
063  @Override
064  public void write(DataOutput out) throws IOException {
065    out.writeLong(capacity);
066    out.writeLong(used);
067    out.writeLong(remaining);
068  }
069
070  @Override
071  public void readFields(DataInput in) throws IOException {
072    capacity = in.readLong();
073    used = in.readLong();
074    remaining = in.readLong();
075  }
076}