gr.uoa.di.madgik.grs.record.field.mediation
Class MediatingInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by gr.uoa.di.madgik.grs.record.field.mediation.MediatingInputStream
All Implemented Interfaces:
Closeable

public class MediatingInputStream
extends InputStream

This class extends the InputStream providing a utility by which a client can access the payload of a Field without needing to take actions depending on whether the full payload of the field is locally available or it is transfered using a transport directive of IBuffer.TransportDirective.Partial. Its function makes sure that additional payload is requested whenever more data is requested. To avoid unnecessary data traffic, additional payload requests are made whenever the client needs to access more data than what is already available. If a client knows beforehand that he is going to need the full payload of the field, an alternative would be to make a request through Field.makeAvailable() to make sure the full payload is available once the invocation is completed. The amount of data that is transfered and made available on every request is subject to the specific FieldDefinition and more particularly to the value set using FieldDefinition.setChunkSize(int). If the data is already available, then no remote request is needed or performed.

Author:
gpapanikos

Constructor Summary
protected MediatingInputStream(Field field)
          Creates a new instance and uses Field.getInputStream() to retrieve the field's input stream
 
Method Summary
 int available()
          
 void close()
          
 void mark(int readlimit)
          
 boolean markSupported()
          
 int read()
          
 int read(byte[] b)
          
 int read(byte[] b, int off, int len)
          
 void reset()
          
 long skip(long n)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MediatingInputStream

protected MediatingInputStream(Field field)
                        throws IOException,
                               GRS2RecordMediationException
Creates a new instance and uses Field.getInputStream() to retrieve the field's input stream

Parameters:
field - the field for which the payload data needs mediation
Throws:
IOException - The field's input stream could not be provided
GRS2RecordMediationException - No field provided
Method Detail

markSupported

public boolean markSupported()

Overrides:
markSupported in class InputStream
See Also:
InputStream.markSupported()

mark

public void mark(int readlimit)

Overrides:
mark in class InputStream
See Also:
InputStream.mark(int)

close

public void close()
           throws IOException

Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException
See Also:
InputStream.close()

available

public int available()
              throws IOException

Overrides:
available in class InputStream
Throws:
IOException
See Also:
InputStream.available()

read

public int read()
         throws IOException

Before forwarding the request to the underlying InputStream, it is checked if there is one byte available in the underlying InputStream and if there isn't, a request for more data is send

Specified by:
read in class InputStream
Throws:
IOException
See Also:
InputStream.read()

read

public int read(byte[] b)
         throws IOException

Before forwarding the request to the underlying InputStream, it is checked if there are b.length bytes available in the underlying InputStream and if there aren't, a request for more data is send

Overrides:
read in class InputStream
Throws:
IOException
See Also:
InputStream.read(byte[])

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException

Before forwarding the request to the underlying InputStream, it is checked if there are len bytes available in the underlying InputStream and if there aren't, a request for more data is send

Overrides:
read in class InputStream
Throws:
IOException
See Also:
InputStream.read(byte[], int, int)

reset

public void reset()
           throws IOException

Overrides:
reset in class InputStream
Throws:
IOException
See Also:
InputStream.reset()

skip

public long skip(long n)
          throws IOException

Overrides:
skip in class InputStream
Throws:
IOException
See Also:
InputStream.skip(long)


Copyright © 2012. All Rights Reserved.