// Path: giraffa-core/src/test/java/org/apache/giraffa/GiraffaTestUtils.java
// public static void printFileStatus(FileStatus fileStat) throws IOException {
//   printFileStatus(fileStat, -1);
// }


import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.EnumSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.fs.FileAlreadyExistsException;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.fs.CreateFlag;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException;
import org.apache.hadoop.io.IOUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.apache.giraffa.GiraffaTestUtils.printFileStatus;
import static org.apache.hadoop.fs.CreateFlag.APPEND;
import static org.apache.hadoop.fs.CreateFlag.CREATE;
import static org.apache.hadoop.fs.CreateFlag.OVERWRITE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
    EnumSet<CreateFlag> flags = EnumSet.of(CREATE);
    FSDataOutputStream fsDataOutputStream = grfs.create(path, permission,
            flags, bufferSize, replication, blockSize, null);
    for(int j = 0; j < LEN1; j++) {
      fsDataOutputStream.write('c');
    }
    fsDataOutputStream.close();

    flags = EnumSet.of(OVERWRITE);
    fsDataOutputStream = grfs.create(path, permission, flags, bufferSize,
            replication, blockSize, null);
    for(int j = 0; j < LEN2; j++) {
      fsDataOutputStream.write('c');
    }
    fsDataOutputStream.close();

    FileStatus files[] = grfs.listStatus(new Path("."));
    printFileStatus(files);
    assertEquals(1, files.length);
    assertEquals(LEN2, files[0].getLen());
  }

  @Test
  public void testCanCreateNewFileWithCreateAndOverwriteFlag()
          throws IOException {
    EnumSet<CreateFlag> flags = EnumSet.of(CREATE, OVERWRITE);
    grfs.create(path, permission, flags, bufferSize, replication,
            blockSize, null);

    FileStatus files[] = grfs.listStatus(new Path("."));
// Path: giraffa-core/src/test/java/org/apache/giraffa/GiraffaTestUtils.java
// public static void printFileStatus(FileStatus fileStat) throws IOException {
//   printFileStatus(fileStat, -1);
// }


// Path: giraffa-core/src/test/java/org/apache/giraffa/TestCreate.java
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.EnumSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.fs.FileAlreadyExistsException;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.fs.CreateFlag;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException;
import org.apache.hadoop.io.IOUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.apache.giraffa.GiraffaTestUtils.printFileStatus;
import static org.apache.hadoop.fs.CreateFlag.APPEND;
import static org.apache.hadoop.fs.CreateFlag.CREATE;
import static org.apache.hadoop.fs.CreateFlag.OVERWRITE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

    EnumSet<CreateFlag> flags = EnumSet.of(CREATE);
    FSDataOutputStream fsDataOutputStream = grfs.create(path, permission,
            flags, bufferSize, replication, blockSize, null);
    for(int j = 0; j < LEN1; j++) {
      fsDataOutputStream.write('c');
    }
    fsDataOutputStream.close();

    flags = EnumSet.of(OVERWRITE);
    fsDataOutputStream = grfs.create(path, permission, flags, bufferSize,
            replication, blockSize, null);
    for(int j = 0; j < LEN2; j++) {
      fsDataOutputStream.write('c');
    }
    fsDataOutputStream.close();

    FileStatus files[] = grfs.listStatus(new Path("."));
    printFileStatus(files);
    assertEquals(1, files.length);
    assertEquals(LEN2, files[0].getLen());
  }

  @Test
  public void testCanCreateNewFileWithCreateAndOverwriteFlag()
          throws IOException {
    EnumSet<CreateFlag> flags = EnumSet.of(CREATE, OVERWRITE);
    grfs.create(path, permission, flags, bufferSize, replication,
            blockSize, null);

    FileStatus files[] = grfs.listStatus(new Path("."));
    printFileStatus(files);