Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.common » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.pdfbox.pdmodel.common;
   18   
   19   import java.io.ByteArrayInputStream;
   20   import java.io.IOException;
   21   import java.io.InputStream;
   22   import java.io.OutputStream;
   23   
   24   import java.util.List;
   25   
   26   import org.apache.pdfbox.cos.COSBase;
   27   import org.apache.pdfbox.cos.COSStream;
   28   
   29   import org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
   30   
   31   /**
   32    * A PDStream represents a stream in a PDF document.  Streams are tied to a single
   33    * PDF document.
   34    *
   35    * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
   36    * @version $Revision: 1.2 $
   37    */
   38   public class PDMemoryStream extends PDStream
   39   {
   40       private byte[] data;
   41   
   42       /**
   43        * This will create a new PDStream object.
   44        *
   45        * @param buffer The data for this in memory stream.
   46        */
   47       public PDMemoryStream( byte[] buffer )
   48       {
   49           data = buffer;
   50       }
   51   
   52   
   53   
   54       /**
   55        * If there are not compression filters on the current stream then this
   56        * will add a compression filter, flate compression for example.
   57        */
   58       public void addCompression()
   59       {
   60           //no compression to add
   61       }
   62   
   63   
   64   
   65       /**
   66        * Convert this standard java object to a COS object.
   67        *
   68        * @return The cos object that matches this Java object.
   69        */
   70       public COSBase getCOSObject()
   71       {
   72           throw new UnsupportedOperationException( "not supported for memory stream" );
   73       }
   74   
   75       /**
   76        * This will get a stream that can be written to.
   77        *
   78        * @return An output stream to write data to.
   79        *
   80        * @throws IOException If an IO error occurs during writing.
   81        */
   82       public OutputStream createOutputStream() throws IOException
   83       {
   84           throw new UnsupportedOperationException( "not supported for memory stream" );
   85       }
   86   
   87       /**
   88        * This will get a stream that can be read from.
   89        *
   90        * @return An input stream that can be read from.
   91        *
   92        * @throws IOException If an IO error occurs during reading.
   93        */
   94       public InputStream createInputStream() throws IOException
   95       {
   96           return new ByteArrayInputStream( data );
   97       }
   98   
   99       /**
  100        * This will get a stream with some filters applied but not others.  This is useful
  101        * when doing images, ie filters = [flate,dct], we want to remove flate but leave dct
  102        *
  103        * @param stopFilters A list of filters to stop decoding at.
  104        * @return A stream with decoded data.
  105        * @throws IOException If there is an error processing the stream.
  106        */
  107       public InputStream getPartiallyFilteredStream( List stopFilters ) throws IOException
  108       {
  109           return createInputStream();
  110       }
  111   
  112       /**
  113        * Get the cos stream associated with this object.
  114        *
  115        * @return The cos object that matches this Java object.
  116        */
  117       public COSStream getStream()
  118       {
  119           throw new UnsupportedOperationException( "not supported for memory stream" );
  120       }
  121   
  122       /**
  123        * This will get the length of the filtered/compressed stream.  This is readonly in the
  124        * PD Model and will be managed by this class.
  125        *
  126        * @return The length of the filtered stream.
  127        */
  128       public int getLength()
  129       {
  130           return data.length;
  131       }
  132   
  133       /**
  134        * This will get the list of filters that are associated with this stream.  Or
  135        * null if there are none.
  136        * @return A list of all encoding filters to apply to this stream.
  137        */
  138       public List getFilters()
  139       {
  140           return null;
  141       }
  142   
  143       /**
  144        * This will set the filters that are part of this stream.
  145        *
  146        * @param filters The filters that are part of this stream.
  147        */
  148       public void setFilters( List filters )
  149       {
  150           throw new UnsupportedOperationException( "not supported for memory stream" );
  151       }
  152   
  153       /**
  154        * Get the list of decode parameters.  Each entry in the list will refer to
  155        * an entry in the filters list.
  156        *
  157        * @return The list of decode parameters.
  158        *
  159        * @throws IOException if there is an error retrieving the parameters.
  160        */
  161       public List getDecodeParams() throws IOException
  162       {
  163           return null;
  164       }
  165   
  166       /**
  167        * This will set the list of decode params.
  168        *
  169        * @param decodeParams The list of decode params.
  170        */
  171       public void setDecodeParams( List decodeParams )
  172       {
  173           //do nothing
  174       }
  175   
  176       /**
  177        * This will get the file specification for this stream.  This is only
  178        * required for external files.
  179        *
  180        * @return The file specification.
  181        */
  182       public PDFileSpecification getFile()
  183       {
  184           return null;
  185       }
  186   
  187       /**
  188        * Set the file specification.
  189        * @param f The file specification.
  190        */
  191       public void setFile( PDFileSpecification f )
  192       {
  193           //do nothing.
  194       }
  195   
  196       /**
  197        * This will get the list of filters that are associated with this stream.  Or
  198        * null if there are none.
  199        * @return A list of all encoding filters to apply to this stream.
  200        */
  201       public List getFileFilters()
  202       {
  203           return null;
  204       }
  205   
  206       /**
  207        * This will set the filters that are part of this stream.
  208        *
  209        * @param filters The filters that are part of this stream.
  210        */
  211       public void setFileFilters( List filters )
  212       {
  213           //do nothing.
  214       }
  215   
  216       /**
  217        * Get the list of decode parameters.  Each entry in the list will refer to
  218        * an entry in the filters list.
  219        *
  220        * @return The list of decode parameters.
  221        *
  222        * @throws IOException if there is an error retrieving the parameters.
  223        */
  224       public List getFileDecodeParams() throws IOException
  225       {
  226           return null;
  227       }
  228   
  229       /**
  230        * This will set the list of decode params.
  231        *
  232        * @param decodeParams The list of decode params.
  233        */
  234       public void setFileDecodeParams( List decodeParams )
  235       {
  236           //do nothing
  237       }
  238   
  239       /**
  240        * This will copy the stream into a byte array.
  241        *
  242        * @return The byte array of the filteredStream
  243        * @throws IOException When getFilteredStream did not work
  244        */
  245       public byte[] getByteArray() throws IOException
  246       {
  247           return data;
  248       }
  249   
  250       /**
  251        * Get the metadata that is part of the document catalog.  This will
  252        * return null if there is no meta data for this object.
  253        *
  254        * @return The metadata for this object.
  255        */
  256       public PDMetadata getMetadata()
  257       {
  258           return null;
  259       }
  260   
  261       /**
  262        * Set the metadata for this object.  This can be null.
  263        *
  264        * @param meta The meta data for this object.
  265        */
  266       public void setMetadata( PDMetadata meta )
  267       {
  268           //do nothing
  269       }
  270   }

Home » pdfbox-1.1.0-src » org.apache.pdfbox.pdmodel.common » [javadoc | source]