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.

XSLFFontData.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.xslf.usermodel;
  20. import java.io.IOException;
  21. import java.io.InputStream;
  22. import java.io.OutputStream;
  23. import org.apache.poi.ooxml.POIXMLDocumentPart;
  24. import org.apache.poi.openxml4j.opc.PackagePart;
  25. import org.apache.poi.util.Beta;
  26. /**
  27. * A container for fontdata files, i.e. MTX fonts derived from
  28. * true (TTF) or open (OTF) type fonts.
  29. *
  30. * @since POI 4.1.0
  31. */
  32. @Beta
  33. public class XSLFFontData extends POIXMLDocumentPart {
  34. /**
  35. * Create a new XSLFFontData node
  36. */
  37. @SuppressWarnings("unused")
  38. protected XSLFFontData() {
  39. super();
  40. }
  41. /**
  42. * Construct XSLFFontData from a package part
  43. *
  44. * @param part the package part holding the ole data
  45. */
  46. @SuppressWarnings("unused")
  47. public XSLFFontData(final PackagePart part) {
  48. super(part);
  49. }
  50. public InputStream getInputStream() throws IOException {
  51. return getPackagePart().getInputStream();
  52. }
  53. public OutputStream getOutputStream() {
  54. final PackagePart pp = getPackagePart();
  55. pp.clear();
  56. return pp.getOutputStream();
  57. }
  58. /**
  59. * XSLFFontData objects store the actual content in the part directly without keeping a
  60. * copy like all others therefore we need to handle them differently.
  61. */
  62. @Override
  63. protected void prepareForCommit() {
  64. // do not clear the part here
  65. }
  66. public void setData(final byte[] data) throws IOException {
  67. try (final OutputStream os = getPackagePart().getOutputStream()) {
  68. os.write(data);
  69. }
  70. }
  71. }