| | |
| | | |
| | | import java.io.Closeable; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.CharBuffer; |
| | |
| | | import java.util.concurrent.ThreadFactory; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | import java.util.zip.DataFormatException; |
| | | import java.util.zip.Deflater; |
| | | import java.util.zip.Inflater; |
| | |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | /** |
| | | * Common utility methods. |
| | | */ |
| | | public final class StaticUtils { |
| | | |
| | | private static final String DEFAULT_LOGGER_NAME = "org.forgerock.opendj.ldap"; |
| | | |
| | | /** |
| | | * The debug logger which should be used by the SDK. |
| | | * The default logger used by the SDK if there is no appropriate specific logger. |
| | | */ |
| | | public static final Logger DEBUG_LOG = Logger.getLogger("org.forgerock.opendj.ldap"); |
| | | public static final Logger DEFAULT_LOG = LoggerFactory.getLogger(DEFAULT_LOGGER_NAME); |
| | | |
| | | /** |
| | | * The logger used by the SDK for controls related features. |
| | | */ |
| | | public static final Logger CONTROLS_LOG = LoggerFactory.getLogger(DEFAULT_LOGGER_NAME + ".controls"); |
| | | |
| | | /** |
| | | * The logger used by the SDK for schema related features. |
| | | */ |
| | | public static final Logger SCHEMA_LOG = LoggerFactory.getLogger(DEFAULT_LOGGER_NAME + ".schema"); |
| | | |
| | | /** |
| | | * The logger used by the SDK for IO related features (buffers, readers, writers). |
| | | */ |
| | | public static final Logger IO_LOG = LoggerFactory.getLogger(DEFAULT_LOGGER_NAME + ".io"); |
| | | |
| | | /** |
| | | * Indicates whether the SDK is being used in debug mode. In debug mode |
| | |
| | | compress(inputBytes, 0, inputBytes.length, outputBytes, 0, outputBytes.length); |
| | | |
| | | if (compressedSize != -1) { |
| | | if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINE)) { |
| | | StaticUtils.DEBUG_LOG.fine(String.format("Compression %d/%d%n", compressedSize, |
| | | inputBytes.length)); |
| | | } |
| | | |
| | | DEFAULT_LOG.debug("Compression {}/{}", compressedSize, inputBytes.length); |
| | | output.append(outputBytes, 0, compressedSize); |
| | | return true; |
| | | } |
| | |
| | | // Format the year yyyy. |
| | | int n = calendar.get(Calendar.YEAR); |
| | | if (n < 0) { |
| | | final IllegalArgumentException e = |
| | | new IllegalArgumentException("Year cannot be < 0:" + n); |
| | | StaticUtils.DEBUG_LOG.throwing("GeneralizedTimeSyntax", "format", e); |
| | | final IllegalArgumentException e = new IllegalArgumentException("Year cannot be < 0:" + n); |
| | | throw e; |
| | | } else if (n < 10) { |
| | | sb.append("000"); |
| | |
| | | } |
| | | |
| | | return returnArray; |
| | | } catch (final Exception e) { |
| | | DEBUG_LOG.warning("Unable to encode UTF-8 string " + s); |
| | | |
| | | return s.getBytes(); |
| | | } catch (final UnsupportedEncodingException e) { |
| | | // TODO: I18N |
| | | throw new RuntimeException("Unable to encode UTF-8 string " + s, e); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | if (DEBUG_TO_STDERR) { |
| | | System.err.println(builder.toString()); |
| | | } else if (DEBUG_LOG.isLoggable(Level.SEVERE)) { |
| | | DEBUG_LOG.severe(builder.toString()); |
| | | } else if (DEFAULT_LOG.isErrorEnabled()) { |
| | | // TODO: I18N |
| | | DEFAULT_LOG.error(builder.toString()); |
| | | } |
| | | } |
| | | } |