You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2020/02/21 21:44:50 UTC

[GitHub] [commons-vfs] ottobackwards opened a new pull request #85: VFS-760 Zkprovider

ottobackwards opened a new pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85
 
 
   This PR provides a provider for Zookeeper.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] ecki commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
ecki commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386640875
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   I think you can remove both, isFolder and exists, both will work based on the getType()

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] belugabehr commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
belugabehr commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386604609
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   Woops.  Introduced this mistake.  This is an Exception, not a logging message so you will have to use string concatenation instead:
   
   ```
   throw new FileSystemException("Unable to check existance: " +getName(),
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] belugabehr commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
belugabehr commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386617553
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   I just looked at the `Messages` class and it uses the String formatter, not the SLF4J-style anchors.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] ecki commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
ecki commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386645850
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   > Would you prefer a change to the super function?
   
   Yes I think it should be type.hasChildren(). Not sure if that breaks tests, though. I agree to keep the overwrite for now, but it should check getType so it does not return true on virtual nodes.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] ecki commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
ecki commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386635910
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   > Because the we need to do the attach and not assume the stat has been retrieved.
   
   I don't think that's correct, the staleness of a object is determined by the Cachesstrategy, if you want an attach on each method invocation (or on resolve) you can let VFS do that automatically http://commons.apache.org/proper/commons-vfs/commons-vfs2/apidocs/org/apache/commons/vfs2/CacheStrategy.html

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386669382
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   So, support for File or Folder is not great top to bottom
   This would be part of some effort to make that all work right

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386641240
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   working on it :)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386633521
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   I probably took this approach from looking at the HDFS File Object.  Which also handles the exception message the same way by the way

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386637267
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   Ok @ecki, that makes sense.  I'm not sure why HDFS works that way though... I'll try to find the cache stuff

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386632446
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   Because the we need to do the attach and not assume the stat has been retrieved. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386642337
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   Would you prefer a change to the super function?  

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] belugabehr commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
belugabehr commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386604609
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   Woops.  Introduced this mistake.  This is an Exception, not a logging message so you will have to use string concatenation instead:
   
   ```
   throw new FileSystemException("Unable to check existance: " + getName(),
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] belugabehr commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
belugabehr commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386535511
 
 

 ##########
 File path: pom.xml
 ##########
 @@ -550,6 +553,16 @@
           </exclusion>
         </exclusions>
       </dependency>
+      <dependency>
+        <groupId>org.apache.curator</groupId>
+        <artifactId>curator-client</artifactId>
+        <version>${curator-version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.curator</groupId>
+        <artifactId>curator-recipes</artifactId>
+        <version>${curator-version}</version>
+      </dependency>
 
 Review comment:
   I don't think these should be included in the root POM file since these are specific to the ZKProvider project/module

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386636517
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   I don't think that error code exists in the resources.  I have propagated the HDFS author's act of not adding it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] ecki commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
ecki commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386622698
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   BTW Do,we know why it needs to overwrite the exist method instead of using the abstract version or a doExists() impl? The attaching should be left to the decorator. If this has to do with the file type virtual not working, a comment should state that clearly.
   
   Removing the function would be better than fixing it ,)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] ecki commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
ecki commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386615214
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   We should also use NLS keys (error codes).
   
   BTW i think the VFSException does format the name argument:
   https://github.com/apache/commons-vfs/blob/249d1dc9fb3f2bd5209aaa299c4ed61414f1fd78/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemException.java#L198
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] ecki commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
ecki commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386645850
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   > Would you prefer a change to the super function?
   
   Yes I think it should be type.hasChildren(). Not sure if that breaks tests, though. I agree to keep the overwrite for now, but it should check getType so it does not return true on virtual nodes. (But that part of the api might be a bit unclear..)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386551585
 
 

 ##########
 File path: pom.xml
 ##########
 @@ -550,6 +553,16 @@
           </exclusion>
         </exclusions>
       </dependency>
+      <dependency>
+        <groupId>org.apache.curator</groupId>
+        <artifactId>curator-client</artifactId>
+        <version>${curator-version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.curator</groupId>
+        <artifactId>curator-recipes</artifactId>
+        <version>${curator-version}</version>
+      </dependency>
 
 Review comment:
   Thanks, moved

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [commons-vfs] ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #85: VFS-760 Zkprovider
URL: https://github.com/apache/commons-vfs/pull/85#discussion_r386641924
 
 

 ##########
 File path: commons-vfs2-zookeeper/src/main/java/org/apache/commons/vfs2/provider/zookeeper/ZkFileObject.java
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * 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.commons.vfs2.provider.zookeeper;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileType;
+import org.apache.commons.vfs2.provider.AbstractFileName;
+import org.apache.commons.vfs2.provider.AbstractFileObject;
+import org.apache.commons.vfs2.provider.UriParser;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkFileObject extends AbstractFileObject<ZkFileSystem> {
+
+  private CuratorFramework framework;
+  private String path;
+  private Stat stat;
+
+  protected ZkFileObject(final AbstractFileName name,
+      final ZkFileSystem fileSystem, final CuratorFramework framework,
+      final String path) {
+    super(name, fileSystem);
+    this.framework = Objects.requireNonNull(framework);
+    this.path = Objects.requireNonNull(path);
+  }
+
+  @Override
+  protected long doGetContentSize() throws Exception {
+    return this.stat.getDataLength();
+  }
+
+  @Override
+  protected InputStream doGetInputStream() throws Exception {
+    if (this.stat == null) {
+      throw new FileSystemException("vfs.provider/read-not-file.error",
+          getName());
+    }
+
+    final byte[] data = (this.stat.getDataLength() == 0) ? new byte[0]
+        : framework.getData().forPath(this.path);
+    return new ByteArrayInputStream(data);
+  }
+  
+  @Override
+  protected FileType doGetType() throws Exception {
+    return (this.stat == null) ? FileType.IMAGINARY : FileType.FILE_OR_FOLDER;
+  }
+
+  /**
+   * Checks if this file is a folder by using its file type. ZooKeeper nodes can
+   * always be considered as folders or files.
+   *
+   * @return true if this file is a regular file.
+   * @throws FileSystemException if an error occurs.
+   * @see #getType()
+   * @see FileType#FOLDER
+   */
+  @Override
+  public boolean isFolder() throws FileSystemException {
+    return true;
+  }
+
+  @Override
+  protected String[] doListChildren() throws Exception {
+    if (this.stat == null || this.stat.getNumChildren() == 0) {
+      return new String[0];
+    }
+
+    List<String> children = framework.getChildren().forPath(this.path);
+    return UriParser.encode(children.toArray(new String[0]));
+  }
+
+  @Override
+  protected void doAttach() throws Exception {
+    try {
+      this.stat = this.framework.checkExists().forPath(this.path);
+    } catch (final Exception e) {
+      this.stat = null;
+    }
+  }
+
+  /**
+   * Determines if the file exists.
+   *
+   * @see org.apache.commons.vfs2.provider.AbstractFileObject#exists()
+   * @return boolean true if file exists, false if not
+   */
+  @Override
+  public boolean exists() throws FileSystemException {
+    try {
+      doAttach();
+      return this.stat != null;
+    } catch (final Exception e) {
+      throw new FileSystemException("Unable to check existance: {}", getName(),
 
 Review comment:
   Actually, isFolder won't work.  It checks explicitly for FOLDER and doesn't do FOLDER or FILE_OR_FOLDER.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services