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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. * <br>
  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. */
  36. public class StructuredFieldReader {
  37. /**
  38. * The input stream to read
  39. */
  40. private InputStream inputStream;
  41. /**
  42. * The constructor for the StructuredFieldReader
  43. * @param inputStream the input stream to process
  44. */
  45. public StructuredFieldReader(InputStream inputStream) {
  46. this.inputStream = inputStream;
  47. }
  48. /**
  49. * Get the next structured field as identified by the identifier
  50. * parameter (this must be a valid MO:DCA structured field).
  51. * Note: The returned data does not include the field length and identifier!
  52. * @param identifier the three byte identifier
  53. * @throws IOException if an I/O exception occurred
  54. * @return the next structured field or null when there are no more
  55. */
  56. public byte[] getNext(byte[] identifier) throws IOException {
  57. byte[] bytes = AFPResourceUtil.getNext(identifier, this.inputStream);
  58. if (bytes != null) {
  59. //Users of this class expect the field data without length and identifier
  60. int srcPos = 2 + identifier.length;
  61. byte[] tmp = new byte[bytes.length - srcPos];
  62. System.arraycopy(bytes, srcPos, tmp, 0, tmp.length);
  63. bytes = tmp;
  64. }
  65. return bytes;
  66. }
  67. }