lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marvin Humphrey (JIRA)" <j...@apache.org>
Subject [jira] Commented: (LUCENE-2316) Define clear semantics for Directory.fileLength
Date Sat, 13 Mar 2010 15:50:27 GMT

    [ https://issues.apache.org/jira/browse/LUCENE-2316?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12844906#action_12844906
] 

Marvin Humphrey commented on LUCENE-2316:
-----------------------------------------

Is it really necessary to obtain the length of a file from the Directory? Lucy
doesn't implement that functionality, and we haven't missed it -- we're able
to get away with using the length() method on InStream and OutStream. 

I see that IndexInput and IndexOutput already have length() methods. Can you
simply eliminate all uses of Directory.fileLength() within core and deprecate
it without introducing a new method?

> Define clear semantics for Directory.fileLength
> -----------------------------------------------
>
>                 Key: LUCENE-2316
>                 URL: https://issues.apache.org/jira/browse/LUCENE-2316
>             Project: Lucene - Java
>          Issue Type: Improvement
>          Components: Index
>            Reporter: Shai Erera
>            Priority: Minor
>             Fix For: 3.1
>
>
> On this thread: http://mail-archives.apache.org/mod_mbox/lucene-java-dev/201003.mbox/%3C126142c1003121525v24499625u1589bbef4c0792e7@mail.gmail.com%3E
it was mentioned that Directory's fileLength behavior is not consistent between Directory
implementations if the given file name does not exist. FSDirectory returns a 0 length while
RAMDirectory throws FNFE.
> The problem is that the semantics of fileLength() are not defined. As proposed in the
thread, we'll define the following semantics:
> * Returns the length of the file denoted by <code>name</code> if the file
exists. The return value may be anything between 0 and Long.MAX_VALUE.
> * Throws FileNotFoundException if the file does not exist. Note that you can call dir.fileExists(name)
if you are not sure whether the file exists or not.
> For backwards we'll create a new method w/ clear semantics. Something like:
> {code}
> /**
>  * @deprecated the method will become abstract when #fileLength(name) has been removed.
>  */
> public long getFileLength(String name) throws IOException {
>   long len = fileLength(name);
>   if (len == 0 && !fileExists(name)) {
>     throw new FileNotFoundException(name);
>   }
>   return len;
> }
> {code}
> The first line just calls the current impl. If it throws exception for a non-existing
file, we're ok. The second line verifies whether a 0 length is for an existing file or not
and throws an exception appropriately.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message