@@ -0,0 +1,3289 @@
+/*%0A * Copyright (c) 2017 sadikovi%0A *%0A * Permission is hereby granted, free of charge, to any person obtaining a copy%0A * of this software and associated documentation files (the %22Software%22), to deal%0A * in the Software without restriction, including without limitation the rights%0A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell%0A * copies of the Software, and to permit persons to whom the Software is%0A * furnished to do so, subject to the following conditions:%0A *%0A * The above copyright notice and this permission notice shall be included in all%0A * copies or substantial portions of the Software.%0A *%0A * THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0A * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE%0A * SOFTWARE.%0A */%0A%0Apackage com.github.sadikovi.riff;%0A%0Aimport java.io.IOException;%0Aimport java.util.Iterator;%0A%0Aimport org.apache.hadoop.fs.FileAlreadyExistsException;%0Aimport org.apache.hadoop.fs.FileSystem;%0Aimport org.apache.hadoop.fs.Path;%0A%0Aimport org.apache.spark.sql.catalyst.InternalRow;%0A%0Aclass FileWriter %7B%0A  // suffix for data files%0A  private static final String DATA_FILE_SUFFIX = %22.data%22;%0A%0A  // file system to use for writing a file%0A  private FileSystem fs;%0A  // resolved path for header file%0A  private Path headerPath;%0A  // resolved path for data file%0A  private Path dataPath;%0A  // type description for schema to write%0A  private TypeDescription td;%0A%0A  /**%0A   * Create file writer for path.%0A   * @param fs file system to use%0A   * @param path path to the header file, data path is created from it%0A   * @throws IOException%0A   * @throws FileAlreadyExistsException%0A   */%0A  FileWriter(FileSystem fs, Path path, TypeDescription td) throws IOException %7B%0A    this.fs = fs;%0A    this.headerPath = fs.makeQualified(path);%0A    this.dataPath = makeDataPath(headerPath);%0A    this.td = td;%0A%0A    if (this.fs.exists(headerPath)) %7B%0A      throw new FileAlreadyExistsException(%22Already exists: %22 + headerPath);%0A    %7D%0A    if (this.fs.exists(dataPath)) %7B%0A      throw new FileAlreadyExistsException(%0A        %22Data path already exists: %22 + dataPath + %22. Data path is created from provided path %22 +%0A        path + %22 and also should not exist when %22 + %22creating writer%22);%0A    %7D%0A  %7D%0A%0A  /**%0A   * Append data file suffix to the path, suffix is always the last block in file name.%0A   * @param path header path%0A   * @return data path%0A   */%0A  static Path makeDataPath(Path path) %7B%0A    return path.suffix(DATA_FILE_SUFFIX);%0A  %7D%0A%0A  /**%0A   * Return header path for writer.%0A   * @return header path%0A   */%0A  public Path headerPath() %7B%0A    return headerPath;%0A  %7D%0A%0A  /**%0A   * Return data path for writer.%0A   * @return data path%0A   */%0A  public Path dataPath() %7B%0A    return dataPath;%0A  %7D%0A%0A  public void writeRows(Iterator%3CInternalRow%3E iter) %7B%0A    // TODO: implement writing rows%0A  %7D%0A%0A  @Override%0A  public String toString() %7B%0A    return %22FileWriter%5Bheader=%22 + headerPath + %22, data=%22 + dataPath + %22, type_desc=%22 + td + %22%5D%22;%0A  %7D%0A%7D%0A

add file writer