TrueZIP Kernel 7.0-rc1

de.schlichtherle.truezip.entry
Class EntryName

java.lang.Object
  extended by de.schlichtherle.truezip.entry.EntryName
All Implemented Interfaces:
Serializable, Comparable<EntryName>
Direct Known Subclasses:
FsEntryName

@Immutable
public class EntryName
extends Object
implements Serializable, Comparable<EntryName>

Addresses an entry in an entry container. An entry name is usually constructed from a Uniform Resource Identifier in order to assert the following additional syntax constraints:

  1. The URI must be relative, i.e. it must not have a scheme.
  2. The URI must not have an authority.
  3. The URI must not have a fragment.

Examples for valid entry name URIs are:

Examples for invalid entry name URIs are:

Although this class is declared to be immutable, it's not declared to be final solely in order to enable subclassing for the purpose of adding even more constraints in the sub class constructor while still being able to use references to this base class polymorphically.

This class supports serialization with both ObjectOutputStream and XMLEncoder.

Author:
Christian Schlichtherle
See Also:
Entry.getName(), Serialized Form

Field Summary
static String SEPARATOR
          The separator string for file names in an entry name, which is "/".
static char SEPARATOR_CHAR
          The separator character for file names in an entry name, which is 47.
private static long serialVersionUID
           
private  URI uri
           
 
Constructor Summary
EntryName(EntryName parent, EntryName member)
          Constructs a new entry name by resolving the given member entry name against the given parent entry name.
EntryName(String uri)
          Constructs a new entry name by calling new URI(uri) and parsing the resulting URI.
EntryName(URI uri)
          Constructs a new entry name by parsing the given URI.
 
Method Summary
 int compareTo(EntryName that)
          Implements a natural ordering which is consistent with equals(Object).
static EntryName create(String uri)
          Constructs a new entry name by constructing a new URI from the given string representation and parsing the result.
static EntryName create(String path, String query)
          Constructs a new entry name by constructing a new URI from the given path and query elements and parsing the result.
static EntryName create(URI uri)
          Constructs a new entry name by parsing the given URI.
 boolean equals(Object that)
          Returns true iff the given object is a entry name and its URI equals the URI of this entry name.
 String getPath()
          Returns the path of this entry name.
 String getQuery()
          Returns the query of this entry name.
 URI getUri()
          Returns the URI of this entry name.
 int hashCode()
          Returns a hash code which is consistent with equals(Object).
private  boolean invariants()
           
private  void parse(URI uri)
           
private static String quote(Object s)
           
private  void readObject(ObjectInputStream in)
           
 String toString()
          Equivalent to calling URI.toString() on getUri().
private  void writeObject(ObjectOutputStream out)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

SEPARATOR

public static final String SEPARATOR
The separator string for file names in an entry name, which is "/".

See Also:
SEPARATOR_CHAR, Constant Field Values

SEPARATOR_CHAR

public static final char SEPARATOR_CHAR
The separator character for file names in an entry name, which is 47.

See Also:
SEPARATOR, Constant Field Values

uri

@NonNull
private URI uri
Constructor Detail

EntryName

public EntryName(@NonNull
                 String uri)
          throws URISyntaxException
Constructs a new entry name by calling new URI(uri) and parsing the resulting URI.

Parameters:
uri - the URI string representation.
Throws:
URISyntaxException - if uri does not conform to the syntax constraints for entry names.

EntryName

public EntryName(@NonNull
                 URI uri)
          throws URISyntaxException
Constructs a new entry name by parsing the given URI.

Parameters:
uri - the URI.
Throws:
URISyntaxException - if uri does not conform to the syntax constraints for entry names.

EntryName

public EntryName(@NonNull
                 EntryName parent,
                 @NonNull
                 EntryName member)
Constructs a new entry name by resolving the given member entry name against the given parent entry name. Note that the URI of the parent entry name is considered to name a directory even if it's not ending with a SEPARATOR_CHAR, so calling this constructor with "foo" and "bar" as the URIs for the parent and member entry names respectively will result in the URI "foo/bar" for the resulting entry name.

Parameters:
parent - an entry name for the parent.
member - an entry name for the member.
Method Detail

create

@NonNull
public static EntryName create(@NonNull
                                       String uri)
Constructs a new entry name by constructing a new URI from the given string representation and parsing the result. This static factory method calls new EntryName(uri) and wraps any thrown URISyntaxException in an IllegalArgumentException.

Parameters:
uri - the URI string representation.
Returns:
A new entry name.
Throws:
IllegalArgumentException - if uri does not conform to the syntax constraints for entry names.

create

@NonNull
public static EntryName create(@NonNull
                                       String path,
                                       @CheckForNull
                                       String query)
Constructs a new entry name by constructing a new URI from the given path and query elements and parsing the result. This static factory method calls new EntryName(new URI(null, null, path, query, null)) and returns the result.

Parameters:
path - the path.
query - the query.
Returns:
A new entry name.

create

@NonNull
public static EntryName create(@NonNull
                                       URI uri)
Constructs a new entry name by parsing the given URI. This static factory method calls new EntryName(uri) and wraps any thrown URISyntaxException in an IllegalArgumentException.

Parameters:
uri - the URI.
Returns:
A new entry name.
Throws:
IllegalArgumentException - if uri does not conform to the syntax constraints for entry names.

writeObject

private void writeObject(@NonNull
                         ObjectOutputStream out)
                  throws IOException
Throws:
IOException

readObject

private void readObject(@NonNull
                        ObjectInputStream in)
                 throws IOException,
                        ClassNotFoundException
Throws:
IOException
ClassNotFoundException

parse

private void parse(@NonNull
                   URI uri)
            throws URISyntaxException
Throws:
URISyntaxException

quote

private static String quote(Object s)

invariants

private boolean invariants()

getPath

@NonNull
public final String getPath()
Returns the path of this entry name. Equivalent to getUri().getPath().

Returns:
The path of this entry name.

getQuery

@CheckForNull
public final String getQuery()
Returns the query of this entry name. Equivalent to getUri().getQuery().

Returns:
The query of this entry name.

getUri

@NonNull
public final URI getUri()
Returns the URI of this entry name.

Returns:
The URI of this entry name.

equals

public final boolean equals(@CheckForNull
                            Object that)
Returns true iff the given object is a entry name and its URI equals the URI of this entry name.

Overrides:
equals in class Object

compareTo

public final int compareTo(@NonNull
                           EntryName that)
Implements a natural ordering which is consistent with equals(Object).

Specified by:
compareTo in interface Comparable<EntryName>

hashCode

public final int hashCode()
Returns a hash code which is consistent with equals(Object).

Overrides:
hashCode in class Object

toString

@NonNull
public final String toString()
Equivalent to calling URI.toString() on getUri().

Overrides:
toString in class Object

TrueZIP Kernel 7.0-rc1

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.