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.

FileHandlerKnown.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.stress;
  16. import java.io.File;
  17. import java.io.InputStream;
  18. import java.lang.reflect.InvocationTargetException;
  19. @SuppressWarnings("unused")
  20. public enum FileHandlerKnown {
  21. HDGF,
  22. HMEF,
  23. HPBF,
  24. HPSF,
  25. HSLF,
  26. HSMF,
  27. HSSF,
  28. HWPF,
  29. OPC,
  30. POIFS,
  31. XDGF,
  32. XSLF,
  33. XSSFB,
  34. XSSF,
  35. XWPF,
  36. OWPF,
  37. NULL
  38. ;
  39. public FileHandler getHandler() {
  40. try {
  41. // Because of no-scratchpad handling, we need to resort to reflection here
  42. String n = name().replace("NULL", "Null");
  43. return (FileHandler)Class.forName("org.apache.poi.stress." + n + "FileHandler").getDeclaredConstructor().newInstance();
  44. } catch (RuntimeException | ClassNotFoundException | NoSuchMethodException | InstantiationException |
  45. IllegalAccessException | InvocationTargetException e) {
  46. return new NullFileHandler();
  47. }
  48. }
  49. private static class NullFileHandler implements FileHandler {
  50. @Override
  51. public void handleFile(InputStream stream, String path) {}
  52. @Override
  53. public void handleExtracting(File file) {}
  54. @Override
  55. public void handleAdditional(File file) {}
  56. }
  57. }