You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StreamCache.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. /* $Id$ */
  18. package org.apache.fop.pdf;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. /**
  22. * Interface used to store the bytes for a PDFStream. It's actually a generic
  23. * cached byte array. There's a factory that returns either an
  24. * in-memory or tempfile based implementation based on a
  25. * cacheToFile setting.
  26. */
  27. public interface StreamCache {
  28. /**
  29. * Get the current OutputStream. Do not store it - it may change
  30. * from call to call.
  31. *
  32. * @return an output stream for this cache
  33. * @throws IOException if there is an IO error
  34. */
  35. OutputStream getOutputStream() throws IOException;
  36. /**
  37. * Convenience method for writing data to the stream cache.
  38. * @param data byte array to write
  39. * @throws IOException if there is an IO error
  40. */
  41. void write(byte[] data) throws IOException;
  42. /**
  43. * Outputs the cached bytes to the given stream.
  44. *
  45. * @param out the stream to write to
  46. * @return the number of bytes written
  47. * @throws IOException if there is an IO error
  48. */
  49. int outputContents(OutputStream out) throws IOException;
  50. /**
  51. * Returns the current size of the stream.
  52. *
  53. * @return the size of the cache
  54. * @throws IOException if there is an IO error
  55. */
  56. int getSize() throws IOException;
  57. /**
  58. * Clears and resets the cache.
  59. *
  60. * @throws IOException if there is an IO error
  61. */
  62. void clear() throws IOException;
  63. }