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.

StructuredFieldReader.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.afp.util;
  19. import java.io.IOException;
  20. import java.io.InputStream;
  21. /**
  22. * A helper class to read structured fields from a MO:DCA document. Each
  23. * component of a mixed object document is explicitly defined and delimited
  24. * in the data. This is accomplished through the use of MO:DCA data structures,
  25. * called structured fields. Structured fields are used to envelop document
  26. * components and to provide commands and information to applications using
  27. * the data. Structured fields may contain one or more parameters. Each
  28. * parameter provides one value from a set of values defined by the architecture.
  29. * <p/>
  30. * MO:DCA structured fields consist of two parts: an introducer that identifies
  31. * the length and type of the structured field, and data that provides the
  32. * structured field's effect. The data is contained in a set of parameters,
  33. * which can consist of other data structures and data elements. The maximum
  34. * length of a structured field is 32767 bytes.
  35. * <p/>
  36. */
  37. public class StructuredFieldReader {
  38. /**
  39. * The input stream to read
  40. */
  41. private InputStream inputStream;
  42. /**
  43. * The constructor for the StructuredFieldReader
  44. * @param inputStream the input stream to process
  45. */
  46. public StructuredFieldReader(InputStream inputStream) {
  47. this.inputStream = inputStream;
  48. }
  49. /**
  50. * Get the next structured field as identified by the identifier
  51. * parameter (this must be a valid MO:DCA structured field).
  52. * Note: The returned data does not include the field length and identifier!
  53. * @param identifier the three byte identifier
  54. * @throws IOException if an I/O exception occurred
  55. * @return the next structured field or null when there are no more
  56. */
  57. public byte[] getNext(byte[] identifier) throws IOException {
  58. byte[] bytes = AFPResourceUtil.getNext(identifier, this.inputStream);
  59. if (bytes != null) {
  60. //Users of this class expect the field data without length and identifier
  61. int srcPos = 2 + identifier.length;
  62. byte[] tmp = new byte[bytes.length - srcPos];
  63. System.arraycopy(bytes, srcPos, tmp, 0, tmp.length);
  64. bytes = tmp;
  65. }
  66. return bytes;
  67. }
  68. }