hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chl...@apache.org
Subject [hama] branch componentization updated: Add default local FileSystem type class.
Date Sun, 10 Mar 2019 17:08:13 GMT
This is an automated email from the ASF dual-hosted git repository.

chl501 pushed a commit to branch componentization
in repository https://gitbox.apache.org/repos/asf/hama.git


The following commit(s) were added to refs/heads/componentization by this push:
     new 67ecc55  Add default local FileSystem type class.
67ecc55 is described below

commit 67ecc55c807775d65c61fd9a441081a50bbf768f
Author: Chiahung Lin <chl501@apache.org>
AuthorDate: Sun Mar 10 18:07:21 2019 +0100

    Add default local FileSystem type class.
---
 .../main/scala/org/apache/hama/fs/FileSystem.scala | 63 ++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/commons.v2/src/main/scala/org/apache/hama/fs/FileSystem.scala b/commons.v2/src/main/scala/org/apache/hama/fs/FileSystem.scala
new file mode 100644
index 0000000..cae2503
--- /dev/null
+++ b/commons.v2/src/main/scala/org/apache/hama/fs/FileSystem.scala
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.fs
+
+import java.io.IOException
+import java.nio.file.Path
+import java.nio.file.Paths
+import scala.util.Either
+import scala.util.Try
+
+trait FileSystem {
+
+  def close: Either[IOException, Unit]
+
+  def path(paths: String*): Either[Throwable, Path]
+
+  def create(path: Path): Either[Throwable, Path]
+
+  def remove(path: Path): Either[Throwable, Path]
+
+  def exist(path: Path): Boolean 
+
+}
+
+object FileSystem {
+
+  def apply(implicit fs: FileSystem): FileSystem = fs
+
+  def local() = apply(localFS)
+
+  implicit val localFS = new FileSystem {
+
+    override def close: Either[IOException, Unit] = Right()
+  
+    override def path(paths: String*): Either[Throwable, Path] = 
+      Try(Paths.get(paths(0), paths.tail:_*)).toEither
+
+    override def create(path: Path): Either[Throwable, Path] = 
+      Try(path.toFile.createNewFile).map(_ => path).toEither
+
+    override def remove(path: Path): Either[Throwable, Path] = 
+      Try(path.toFile.delete).map(_ => path).toEither
+
+    override def exist(path: Path): Boolean = path.toFile.exists
+
+  }
+
+}


Mime
View raw message