選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

TempFilePOIFSFileSystem.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.poifs.filesystem;
  16. import org.apache.logging.log4j.LogManager;
  17. import org.apache.logging.log4j.Logger;
  18. import org.apache.poi.poifs.nio.FileBackedDataSource;
  19. import org.apache.poi.util.Beta;
  20. import org.apache.poi.util.TempFile;
  21. import java.io.File;
  22. import java.io.IOException;
  23. /**
  24. * An experimental POIFSFileSystem to support the encryption of large files
  25. *
  26. * @since 4.1.1
  27. */
  28. @Beta
  29. public class TempFilePOIFSFileSystem extends POIFSFileSystem {
  30. private static final Logger LOG = LogManager.getLogger(TempFilePOIFSFileSystem.class);
  31. File tempFile;
  32. @Override
  33. protected void createNewDataSource() {
  34. try {
  35. tempFile = TempFile.createTempFile("poifs", ".tmp");
  36. _data = new FileBackedDataSource(tempFile, false);
  37. } catch (IOException e) {
  38. throw new IllegalStateException("Failed to create data source", e);
  39. }
  40. }
  41. @Override
  42. public void close() throws IOException {
  43. if (tempFile != null && tempFile.exists()) {
  44. if (!tempFile.delete()) {
  45. LOG.atDebug().log("temp file was already deleted (probably due to previous call to close this resource)");
  46. }
  47. }
  48. super.close();
  49. }
  50. }