org.jcrom
Class JcrDataProviderImpl

java.lang.Object
  extended by org.jcrom.JcrDataProviderImpl
All Implemented Interfaces:
JcrDataProvider

public class JcrDataProviderImpl
extends java.lang.Object
implements JcrDataProvider

A simple implementation of the JcrDataProvider interface. Developers can implement their own data provider if advanced or custom functionality is needed.

Thanks to Robin Wyles for adding content length.

Author:
Olafur Gauti Gudmundsson

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jcrom.JcrDataProvider
JcrDataProvider.TYPE
 
Field Summary
protected  byte[] bytes
           
protected  long contentLength
           
protected  java.io.File file
           
protected  java.io.InputStream inputStream
           
protected  JcrDataProvider.TYPE type
           
 
Constructor Summary
JcrDataProviderImpl(JcrDataProvider.TYPE type, byte[] bytes)
           
JcrDataProviderImpl(JcrDataProvider.TYPE type, java.io.File file)
           
JcrDataProviderImpl(JcrDataProvider.TYPE type, java.io.InputStream inputStream)
           
JcrDataProviderImpl(JcrDataProvider.TYPE type, java.io.InputStream inputStream, long length)
           
 
Method Summary
 byte[] getBytes()
          Return a byte array.
 long getContentLength()
          Returns the length of the byte array / file / input stream
 java.io.File getFile()
          Return a file.
 java.io.InputStream getInputStream()
          Return an input stream.
 JcrDataProvider.TYPE getType()
          Get the type of content this provider offers.
protected static void write(byte[] bytes, java.io.File destination)
           
protected static void write(java.io.File source, java.io.File destination)
           
protected static void write(java.io.InputStream in, java.io.File destination)
           
 void writeToFile(java.io.File destination)
          Write the content out to the File supplied.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

type

protected final JcrDataProvider.TYPE type

bytes

protected final byte[] bytes

file

protected final java.io.File file

inputStream

protected final java.io.InputStream inputStream

contentLength

protected final long contentLength
Constructor Detail

JcrDataProviderImpl

public JcrDataProviderImpl(JcrDataProvider.TYPE type,
                           byte[] bytes)

JcrDataProviderImpl

public JcrDataProviderImpl(JcrDataProvider.TYPE type,
                           java.io.File file)

JcrDataProviderImpl

public JcrDataProviderImpl(JcrDataProvider.TYPE type,
                           java.io.InputStream inputStream)

JcrDataProviderImpl

public JcrDataProviderImpl(JcrDataProvider.TYPE type,
                           java.io.InputStream inputStream,
                           long length)
Method Detail

getBytes

public byte[] getBytes()
Description copied from interface: JcrDataProvider
Return a byte array.

Specified by:
getBytes in interface JcrDataProvider
Returns:
byte array, or null if type is not JcrDataProvider.TYPE.BYTES

getFile

public java.io.File getFile()
Description copied from interface: JcrDataProvider
Return a file.

Specified by:
getFile in interface JcrDataProvider
Returns:
file, or null if type is not JcrDataProvider.TYPE.FILE

getInputStream

public java.io.InputStream getInputStream()
Description copied from interface: JcrDataProvider
Return an input stream.

Specified by:
getInputStream in interface JcrDataProvider
Returns:
input stream, or null if type is not JcrDataProvider.TYPE.STREAM

getType

public JcrDataProvider.TYPE getType()
Description copied from interface: JcrDataProvider
Get the type of content this provider offers.

Specified by:
getType in interface JcrDataProvider
Returns:
the type of content this provider offers

writeToFile

public void writeToFile(java.io.File destination)
                 throws java.io.IOException
Description copied from interface: JcrDataProvider
Write the content out to the File supplied.

Specified by:
writeToFile in interface JcrDataProvider
Parameters:
destination - the file in question
Throws:
java.io.IOException

write

protected static void write(java.io.InputStream in,
                            java.io.File destination)
                     throws java.io.IOException
Throws:
java.io.IOException

write

protected static void write(byte[] bytes,
                            java.io.File destination)
                     throws java.io.IOException
Throws:
java.io.IOException

write

protected static void write(java.io.File source,
                            java.io.File destination)
                     throws java.io.IOException
Throws:
java.io.IOException

getContentLength

public long getContentLength()
Description copied from interface: JcrDataProvider
Returns the length of the byte array / file / input stream

Specified by:
getContentLength in interface JcrDataProvider
Returns:


Copyright © 2009. All Rights Reserved.