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.

DebugErrorHandler.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. Copyright (c) 2008 Health Market Science, Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package com.healthmarketscience.jackcess.util;
  14. import java.io.IOException;
  15. import com.healthmarketscience.jackcess.Column;
  16. import com.healthmarketscience.jackcess.impl.ByteUtil;
  17. import org.apache.commons.logging.Log;
  18. import org.apache.commons.logging.LogFactory;
  19. /**
  20. * Implementation of ErrorHandler which is useful for generating debug
  21. * information about bad row data (great for bug reports!). After logging a
  22. * debug entry for the failed column, it will return some sort of replacement
  23. * value, see {@link ReplacementErrorHandler}.
  24. *
  25. * @author James Ahlborn
  26. * @usage _general_class_
  27. */
  28. public class DebugErrorHandler extends ReplacementErrorHandler
  29. {
  30. private static final Log LOG = LogFactory.getLog(DebugErrorHandler.class);
  31. /**
  32. * Constructs a DebugErrorHandler which replaces all errored values with
  33. * {@code null}.
  34. */
  35. public DebugErrorHandler() {
  36. }
  37. /**
  38. * Constructs a DebugErrorHandler which replaces all errored values with the
  39. * given Object.
  40. */
  41. public DebugErrorHandler(Object replacement) {
  42. super(replacement);
  43. }
  44. @Override
  45. public Object handleRowError(Column column, byte[] columnData,
  46. Location location, Exception error)
  47. throws IOException
  48. {
  49. if(LOG.isDebugEnabled()) {
  50. LOG.debug("Failed reading column " + column + ", row " +
  51. location + ", bytes " +
  52. ((columnData != null) ?
  53. ByteUtil.toHexString(columnData) : "null"),
  54. error);
  55. }
  56. return super.handleRowError(column, columnData, location, error);
  57. }
  58. }