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.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. Copyright (c) 2008 Health Market Science, Inc.
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with this library; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  14. USA
  15. You can contact Health Market Science at info@healthmarketscience.com
  16. or at the following address:
  17. Health Market Science
  18. 2700 Horizon Drive
  19. Suite 200
  20. King of Prussia, PA 19406
  21. */
  22. package com.healthmarketscience.jackcess;
  23. import java.io.IOException;
  24. import org.apache.commons.logging.Log;
  25. import org.apache.commons.logging.LogFactory;
  26. /**
  27. * Implementation of ErrorHandler which is useful for generating debug
  28. * information about bad row data (great for bug reports!). After logging a
  29. * debug entry for the failed column, it will return some sort of replacement
  30. * value, see {@link ReplacementErrorHandler}.
  31. *
  32. * @author James Ahlborn
  33. */
  34. public class DebugErrorHandler extends ReplacementErrorHandler
  35. {
  36. private static final Log LOG = LogFactory.getLog(DebugErrorHandler.class);
  37. /**
  38. * Constructs a DebugErrorHandler which replaces all errored values with
  39. * {@code null}.
  40. */
  41. public DebugErrorHandler() {
  42. }
  43. /**
  44. * Constructs a DebugErrorHandler which replaces all errored values with the
  45. * given Object.
  46. */
  47. public DebugErrorHandler(Object replacement) {
  48. super(replacement);
  49. }
  50. @Override
  51. public Object handleRowError(Column column,
  52. byte[] columnData,
  53. Table.RowState rowState,
  54. Exception error)
  55. throws IOException
  56. {
  57. if(LOG.isDebugEnabled()) {
  58. LOG.debug("Failed reading column " + column + ", row " +
  59. rowState + ", bytes " +
  60. ((columnData != null) ?
  61. ByteUtil.toHexString(columnData) : "null"),
  62. error);
  63. }
  64. return super.handleRowError(column, columnData, rowState, error);
  65. }
  66. }