org.apache.sling.jcr.classloader.internal

## Class Util

- java.lang.Object
- - org.apache.sling.jcr.classloader.internal.Util

    public class Util
    extends Object

The `Util` provides helper methods for the repository classloader and its class path entry and resource classes.

This class may not be extended or instantiated, it just contains static utility methods.

### Method Summary

All Methods Static Methods Concrete Methods
`static byte[]` `getBytes(javax.jcr.Node node)` Returns the resource as an array of bytes
`static javax.jcr.Property` `getProperty(javax.jcr.Item item)` Resolves the given `item` to a `Property` from which contents can be read.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### getProperty

    public static javax.jcr.Property getProperty(javax.jcr.Item item)
                                          throws javax.jcr.ValueFormatException,
                                                 javax.jcr.RepositoryException

Resolves the given `item` to a `Property` from which contents can be read.

The following mechanism is used to derive the contents:

1. If the `item` is a property, this property is used
2. If the `item` is a node, three steps are tested:
   1. If the node has a `jcr:content` child node, use that child node in the next steps. Otherwise continue with the node.
   2. Check for a `jcr:data` property and use that property if existing.
   3. Otherwise call `getPrimaryItem` method repeatedly until a property is returned or until no more primary item is available.

If no property can be resolved using the above algorithm or if the resulting property is a multivalue property, `null` is returned. Otherwise if the resulting property is a `REFERENCE` property, the node referred to is retrieved and this method is called recursively with the node. Otherwise, the resulting property is returned.

Parameters:
  `item` - The `Item` to resolve to a `Property`.
Returns:
  The resolved `Property` or `null` if the resolved property is a multi-valued property or the `item` is a node which cannot be resolved to a data property.
Throws:
  `javax.jcr.ValueFormatException` - If the `item` resolves to a single-valued `REFERENCE` type property which cannot be resolved to the node referred to.
  `javax.jcr.RepositoryException` - if another error occurrs accessing the repository.

#### getBytes

    public static byte[] getBytes(javax.jcr.Node node)
                           throws IOException,
                                  javax.jcr.RepositoryException

Returns the resource as an array of bytes

Throws:
  `IOException`
  `javax.jcr.RepositoryException`