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.

XSLFObjectData.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.sl.usermodel.ObjectData;
  26. import org.apache.poi.util.Beta;
  27. /**
  28. * An XSLFOleData instance holds the ole binary stream/object
  29. */
  30. @SuppressWarnings("unused")
  31. @Beta
  32. public final class XSLFObjectData extends POIXMLDocumentPart implements ObjectData {
  33. /**
  34. * Create a new XSLFObjectData node
  35. */
  36. /* package */ XSLFObjectData() {
  37. super();
  38. }
  39. /**
  40. * Construct XSLFObjectData from a package part
  41. *
  42. * @param part the package part holding the ole data
  43. *
  44. * @since POI 3.14-Beta1
  45. */
  46. public XSLFObjectData(final PackagePart part) {
  47. super(part);
  48. }
  49. @Override
  50. public InputStream getInputStream() throws IOException {
  51. return getPackagePart().getInputStream();
  52. }
  53. @Override
  54. public OutputStream getOutputStream() {
  55. final PackagePart pp = getPackagePart();
  56. pp.clear();
  57. return pp.getOutputStream();
  58. }
  59. /**
  60. * XSLFObjectData objects store the actual content in the part directly without keeping a
  61. * copy like all others therefore we need to handle them differently.
  62. */
  63. @Override
  64. protected void prepareForCommit() {
  65. // do not clear the part here
  66. }
  67. public void setData(final byte[] data) throws IOException {
  68. try (final OutputStream os = getPackagePart().getOutputStream()) {
  69. os.write(data);
  70. }
  71. }
  72. @Override
  73. public String getOLE2ClassName() {
  74. return null;
  75. }
  76. @Override
  77. public String getFileName() {
  78. return null;
  79. }
  80. }