001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *        http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 */
019
020package org.apache.isis.core.commons.encoding;
021
022import java.io.IOException;
023
024import org.slf4j.Logger;
025import org.slf4j.LoggerFactory;
026
027public class DebugDataOutputExtended extends DataOutputExtendedDecorator {
028
029    private static final Logger LOG = LoggerFactory.getLogger(DebugDataOutputExtended.class);
030
031    public DebugDataOutputExtended(final DataOutputExtended underlying) {
032        super(underlying);
033    }
034
035    @Override
036    public void writeBoolean(final boolean flag) throws IOException {
037        if (LOG.isDebugEnabled()) {
038            LOG.debug("boolean: " + flag);
039        }
040        super.writeBoolean(flag);
041    }
042
043    @Override
044    public void writeBytes(final byte[] value) throws IOException {
045        if (LOG.isDebugEnabled()) {
046            LOG.debug("bytes: (" + value.length + ") " + new String(value));
047        }
048        super.writeBytes(value);
049    }
050
051    @Override
052    public void writeByte(final int value) throws IOException {
053        if (LOG.isDebugEnabled()) {
054            LOG.debug("byte: " + value);
055        }
056        super.writeByte(value);
057    }
058
059    @Override
060    public void writeInt(final int value) throws IOException {
061        if (LOG.isDebugEnabled()) {
062            LOG.debug("int: " + value);
063        }
064        super.writeInt(value);
065    }
066
067    @Override
068    public void writeLong(final long value) throws IOException {
069        if (LOG.isDebugEnabled()) {
070            LOG.debug("long: " + value);
071        }
072        super.writeLong(value);
073    }
074
075    @Override
076    public void writeEncodable(final Object object) throws IOException {
077        if (LOG.isDebugEnabled()) {
078            LOG.debug(">>> object: (" + object + ")");
079        }
080        super.writeEncodable(object);
081    }
082
083    @Override
084    public void writeEncodables(final Object[] objects) throws IOException {
085        if (LOG.isDebugEnabled()) {
086            LOG.debug(">>> objects x" + objects.length);
087        }
088        super.writeEncodables(objects);
089    }
090
091    @Override
092    public void writeUTF(final String str) throws IOException {
093        if (LOG.isDebugEnabled()) {
094            LOG.debug("string: " + str);
095        }
096        super.writeUTF(str);
097    }
098
099    @Override
100    public void writeUTFs(final String[] strings) throws IOException {
101        if (LOG.isDebugEnabled()) {
102            final StringBuffer l = new StringBuffer();
103            for (int i = 0; i < strings.length; i++) {
104                if (i > 0) {
105                    l.append(", ");
106                }
107                l.append(strings[i]);
108            }
109            LOG.debug("list: " + l);
110        }
111        super.writeUTFs(strings);
112    }
113
114}