You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metamodel.apache.org by LosD <gi...@git.apache.org> on 2015/08/07 09:51:27 UTC

[GitHub] metamodel pull request: Adds ability to read folders from FileReso...

GitHub user LosD opened a pull request:

    https://github.com/apache/metamodel/pull/37

    Adds ability to read folders from FileResource and HdfsResource

    This will allow FileResource and HdfsResource to use a folder as a complete resource. It will skip any subfolder and only use files in the folder. Before opening files, they will be sorted them alphabetically by name (actually it uses the natural ordering of the File/FileStatus object, but that is the pathname/url sorted alphabetically).
    
    Fixes METAMODEL-163

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/LosD/metamodel feature/METAMODEL-163-folder-resource

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/metamodel/pull/37.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #37
    
----
commit f11f9607055ce931601cf417d9de009461efddcf
Author: Dennis Du Krøger <de...@humaninference.com>
Date:   2015-08-07T07:45:15Z

    Adds ability to read folders from FileResource and HdfsResource
    
    This will allow FileResource and HdfsResource to use a folder as a complete resource. It will skip any subfolder and only use files in the folder. Before opening files, they will be sorted them alphabetically by name (actually it uses the natural ordering of the File/FileStatus object, but that is the pathname/url sorted alphabetically).

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] metamodel pull request: Adds ability to read folders to FileResour...

Posted by tomaszguzialek <gi...@git.apache.org>.
Github user tomaszguzialek commented on the pull request:

    https://github.com/apache/metamodel/pull/37#issuecomment-129334334
  
    The question is if we still want to support Java 6? I remember a thread on the mailing list where it was decided to craft one more release with Java 6 and then abandon it. I think we had one already...


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] metamodel pull request: Adds ability to read folders to FileResour...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/metamodel/pull/37


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] metamodel pull request: Adds ability to read folders to FileResour...

Posted by LosD <gi...@git.apache.org>.
Github user LosD commented on the pull request:

    https://github.com/apache/metamodel/pull/37#issuecomment-128779418
  
    Argh! No nio in Java 6... Will fix tomorrow


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] metamodel pull request: Adds ability to read folders to FileResour...

Posted by kaspersorensen <gi...@git.apache.org>.
Github user kaspersorensen commented on a diff in the pull request:

    https://github.com/apache/metamodel/pull/37#discussion_r36543367
  
    --- Diff: core/src/main/java/org/apache/metamodel/util/AbstractDirectoryInputStream.java ---
    @@ -0,0 +1,97 @@
    +package org.apache.metamodel.util;
    +
    +import java.io.IOException;
    +import java.io.InputStream;
    +
    +/**
    + * 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.
    + */
    +public abstract class AbstractDirectoryInputStream<T> extends InputStream {
    +    protected T[] _files;
    +    private int _currentFileIndex = -1;
    +    private InputStream _currentInputStream;
    +
    +
    +    @Override
    +    public int read(final byte[] b, final int off, final int len) throws IOException {
    +        if (_currentInputStream != null) {
    +            final int byteCount = _currentInputStream.read(b, off, len);
    +            if (byteCount > 0) {
    +                return byteCount;
    +            }
    +        }
    +
    +        if (!openNextFile()){
    +            return -1; // No more files.
    +        }
    +
    +        return read(b, off, len);
    +    }
    +
    +    @Override
    +    public int read(final byte[] b) throws IOException {
    +        return read(b, 0, b.length);
    +    }
    +
    +    @Override
    +    public int read() throws IOException {
    +        final byte[] b = new byte[1];
    +        int count = read(b, 0 , 1);
    +        if(count < 0){
    +            return -1;
    +        }
    +        return (int) b[0];
    +    }
    +
    +    @Override
    +    public int available() throws IOException {
    +        if(_currentInputStream != null){
    +            return _currentInputStream.available();
    --- End diff --
    
    What about the potential next stream here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] metamodel pull request: Adds ability to read folders to FileResour...

Posted by kaspersorensen <gi...@git.apache.org>.
Github user kaspersorensen commented on a diff in the pull request:

    https://github.com/apache/metamodel/pull/37#discussion_r36543610
  
    --- Diff: core/src/main/java/org/apache/metamodel/util/FileResource.java ---
    @@ -19,16 +19,43 @@
     package org.apache.metamodel.util;
     
     import java.io.File;
    +import java.io.FileFilter;
     import java.io.IOException;
     import java.io.InputStream;
     import java.io.OutputStream;
     import java.io.Serializable;
    +import java.util.Arrays;
    +import java.util.Comparator;
     
     /**
      * {@link File} based {@link Resource} implementation.
      */
     public class FileResource implements Resource, Serializable {
     
    +    private class DirectoryInputStream extends AbstractDirectoryInputStream<File> {
    --- End diff --
    
    Hehe very nitty gritty, but since this nested class is non-static, shouldn't it be declared after static fields?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] metamodel pull request: Adds ability to read folders to FileResour...

Posted by LosD <gi...@git.apache.org>.
Github user LosD commented on the pull request:

    https://github.com/apache/metamodel/pull/37#issuecomment-129349890
  
    This should fix the tests. Let's hope Travis agrees!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] metamodel pull request: Adds ability to read folders to FileResour...

Posted by kaspersorensen <gi...@git.apache.org>.
Github user kaspersorensen commented on a diff in the pull request:

    https://github.com/apache/metamodel/pull/37#discussion_r36576634
  
    --- Diff: core/src/main/java/org/apache/metamodel/util/AbstractDirectoryInputStream.java ---
    @@ -0,0 +1,97 @@
    +package org.apache.metamodel.util;
    +
    +import java.io.IOException;
    +import java.io.InputStream;
    +
    +/**
    + * 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.
    + */
    +public abstract class AbstractDirectoryInputStream<T> extends InputStream {
    +    protected T[] _files;
    +    private int _currentFileIndex = -1;
    +    private InputStream _currentInputStream;
    +
    +
    +    @Override
    +    public int read(final byte[] b, final int off, final int len) throws IOException {
    +        if (_currentInputStream != null) {
    +            final int byteCount = _currentInputStream.read(b, off, len);
    +            if (byteCount > 0) {
    +                return byteCount;
    +            }
    +        }
    +
    +        if (!openNextFile()){
    +            return -1; // No more files.
    +        }
    +
    +        return read(b, off, len);
    +    }
    +
    +    @Override
    +    public int read(final byte[] b) throws IOException {
    +        return read(b, 0, b.length);
    +    }
    +
    +    @Override
    +    public int read() throws IOException {
    +        final byte[] b = new byte[1];
    +        int count = read(b, 0 , 1);
    +        if(count < 0){
    +            return -1;
    +        }
    +        return (int) b[0];
    +    }
    +
    +    @Override
    +    public int available() throws IOException {
    +        if(_currentInputStream != null){
    +            return _currentInputStream.available();
    --- End diff --
    
    Got it :-) 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] metamodel pull request: Adds ability to read folders to FileResour...

Posted by tomaszguzialek <gi...@git.apache.org>.
Github user tomaszguzialek commented on the pull request:

    https://github.com/apache/metamodel/pull/37#issuecomment-129481286
  
    Travis is happy, so I will merge it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] metamodel pull request: Adds ability to read folders to FileResour...

Posted by LosD <gi...@git.apache.org>.
Github user LosD commented on a diff in the pull request:

    https://github.com/apache/metamodel/pull/37#discussion_r36544043
  
    --- Diff: core/src/main/java/org/apache/metamodel/util/FileResource.java ---
    @@ -19,16 +19,43 @@
     package org.apache.metamodel.util;
     
     import java.io.File;
    +import java.io.FileFilter;
     import java.io.IOException;
     import java.io.InputStream;
     import java.io.OutputStream;
     import java.io.Serializable;
    +import java.util.Arrays;
    +import java.util.Comparator;
     
     /**
      * {@link File} based {@link Resource} implementation.
      */
     public class FileResource implements Resource, Serializable {
     
    +    private class DirectoryInputStream extends AbstractDirectoryInputStream<File> {
    --- End diff --
    
    Hmmm... I normally put inline classes and enums as the first elements, but that's a matter of taste. I can move it if you prefer it after static fields.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] metamodel pull request: Adds ability to read folders to FileResour...

Posted by LosD <gi...@git.apache.org>.
Github user LosD commented on a diff in the pull request:

    https://github.com/apache/metamodel/pull/37#discussion_r36543702
  
    --- Diff: core/src/main/java/org/apache/metamodel/util/AbstractDirectoryInputStream.java ---
    @@ -0,0 +1,97 @@
    +package org.apache.metamodel.util;
    +
    +import java.io.IOException;
    +import java.io.InputStream;
    +
    +/**
    + * 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.
    + */
    +public abstract class AbstractDirectoryInputStream<T> extends InputStream {
    +    protected T[] _files;
    +    private int _currentFileIndex = -1;
    +    private InputStream _currentInputStream;
    +
    +
    +    @Override
    +    public int read(final byte[] b, final int off, final int len) throws IOException {
    +        if (_currentInputStream != null) {
    +            final int byteCount = _currentInputStream.read(b, off, len);
    +            if (byteCount > 0) {
    +                return byteCount;
    +            }
    +        }
    +
    +        if (!openNextFile()){
    +            return -1; // No more files.
    +        }
    +
    +        return read(b, off, len);
    +    }
    +
    +    @Override
    +    public int read(final byte[] b) throws IOException {
    +        return read(b, 0, b.length);
    +    }
    +
    +    @Override
    +    public int read() throws IOException {
    +        final byte[] b = new byte[1];
    +        int count = read(b, 0 , 1);
    +        if(count < 0){
    +            return -1;
    +        }
    +        return (int) b[0];
    +    }
    +
    +    @Override
    +    public int available() throws IOException {
    +        if(_currentInputStream != null){
    +            return _currentInputStream.available();
    --- End diff --
    
    Check the JavaDoc for available()... It's only how many is left until a blocking operation. Opening a whole new stream or file is certainly blocking :)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] metamodel pull request: Adds ability to read folders to FileResour...

Posted by kaspersorensen <gi...@git.apache.org>.
Github user kaspersorensen commented on the pull request:

    https://github.com/apache/metamodel/pull/37#issuecomment-128778728
  
    I like what I see. But just had some cosmetic remarks :-) 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] metamodel pull request: Adds ability to read folders to FileResour...

Posted by kaspersorensen <gi...@git.apache.org>.
Github user kaspersorensen commented on a diff in the pull request:

    https://github.com/apache/metamodel/pull/37#discussion_r36543231
  
    --- Diff: core/src/main/java/org/apache/metamodel/util/AbstractDirectoryInputStream.java ---
    @@ -0,0 +1,97 @@
    +package org.apache.metamodel.util;
    +
    +import java.io.IOException;
    +import java.io.InputStream;
    +
    +/**
    --- End diff --
    
    Normally we put the license header above the package declaration. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] metamodel pull request: Adds ability to read folders to FileResour...

Posted by LosD <gi...@git.apache.org>.
Github user LosD commented on a diff in the pull request:

    https://github.com/apache/metamodel/pull/37#discussion_r36543524
  
    --- Diff: core/src/main/java/org/apache/metamodel/util/AbstractDirectoryInputStream.java ---
    @@ -0,0 +1,97 @@
    +package org.apache.metamodel.util;
    +
    +import java.io.IOException;
    +import java.io.InputStream;
    +
    +/**
    --- End diff --
    
    Errr... Whoops!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] metamodel pull request: Adds ability to read folders to FileResour...

Posted by kaspersorensen <gi...@git.apache.org>.
Github user kaspersorensen commented on a diff in the pull request:

    https://github.com/apache/metamodel/pull/37#discussion_r36576641
  
    --- Diff: core/src/main/java/org/apache/metamodel/util/FileResource.java ---
    @@ -19,16 +19,43 @@
     package org.apache.metamodel.util;
     
     import java.io.File;
    +import java.io.FileFilter;
     import java.io.IOException;
     import java.io.InputStream;
     import java.io.OutputStream;
     import java.io.Serializable;
    +import java.util.Arrays;
    +import java.util.Comparator;
     
     /**
      * {@link File} based {@link Resource} implementation.
      */
     public class FileResource implements Resource, Serializable {
     
    +    private class DirectoryInputStream extends AbstractDirectoryInputStream<File> {
    --- End diff --
    
    Nah this is fine, I think you're right. I guess I just almost never make non-static inner classes but here it works quite ok.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---