Example usage for org.apache.commons.io HexDumpOutputStream HexDumpOutputStream

List of usage examples for org.apache.commons.io HexDumpOutputStream HexDumpOutputStream

Introduction

In this page you can find the example usage for org.apache.commons.io HexDumpOutputStream HexDumpOutputStream.

Prototype

public HexDumpOutputStream(LineLevelAppender appender) 

Source Link

Usage

From source file:net.community.chest.gitcloud.facade.backend.git.BackendReceivePackFactory.java

@Override
public ReceivePack create(C request, Repository db)
        throws ServiceNotEnabledException, ServiceNotAuthorizedException {
    final String logPrefix;
    if (request instanceof HttpServletRequest) {
        HttpServletRequest req = (HttpServletRequest) request;
        logPrefix = "create(" + req.getMethod() + ")[" + req.getRequestURI() + "][" + req.getQueryString()
                + "]";
    } else {/*from   w w w .j  av a 2  s .c  om*/
        logPrefix = "create(" + db.getDirectory() + ")";
    }
    if (logger.isDebugEnabled()) {
        logger.debug(logPrefix + ": " + db.getDirectory());
    }

    ReceivePack receive = new ReceivePack(db) {
        @Override
        @SuppressWarnings("synthetic-access")
        public void receive(InputStream input, OutputStream output, OutputStream messages) throws IOException {
            InputStream effIn = input;
            OutputStream effOut = output, effMessages = messages;
            if (logger.isTraceEnabled()) {
                LineLevelAppender inputAppender = new LineLevelAppender() {
                    @Override
                    public void writeLineData(CharSequence lineData) throws IOException {
                        logger.trace(logPrefix + " upload(C): " + lineData);
                    }

                    @Override
                    public boolean isWriteEnabled() {
                        return true;
                    }
                };
                effIn = new TeeInputStream(effIn, new HexDumpOutputStream(inputAppender), true);

                LineLevelAppender outputAppender = new LineLevelAppender() {
                    @Override
                    public void writeLineData(CharSequence lineData) throws IOException {
                        logger.trace(logPrefix + " upload(S): " + lineData);
                    }

                    @Override
                    public boolean isWriteEnabled() {
                        return true;
                    }
                };
                effOut = new TeeOutputStream(effOut, new HexDumpOutputStream(outputAppender));

                if (effMessages != null) {
                    LineLevelAppender messagesAppender = new LineLevelAppender() {
                        @Override
                        public void writeLineData(CharSequence lineData) throws IOException {
                            logger.trace(logPrefix + " upload(M): " + lineData);
                        }

                        @Override
                        public boolean isWriteEnabled() {
                            return true;
                        }
                    };
                    // TODO review the decision to use an AsciiLineOutputStream here
                    effMessages = new TeeOutputStream(effMessages, new AsciiLineOutputStream(messagesAppender));
                }
            }

            super.receive(effIn, effOut, effMessages);
        }
    };
    receive.setTimeout(receiveTimeoutValue);

    // TODO set pushing user identity for reflog
    // receive.setRefLogIdent(new PersonIdent(user.username, user.username + "@" + origin))

    // TODO set advanced options
    // receive.setAllowCreates(user.canCreateRef(repository));
    // receive.setAllowDeletes(user.canDeleteRef(repository));
    // receive.setAllowNonFastForwards(user.canRewindRef(repository));

    // TODO setup the receive hooks
    // receive.setPreReceiveHook(preRcvHook);
    // receive.setPostReceiveHook(postRcvHook);

    return receive;
}

From source file:net.community.chest.gitcloud.facade.backend.git.BackendUploadPackFactory.java

@Override
public UploadPack create(final C request, Repository db)
        throws ServiceNotEnabledException, ServiceNotAuthorizedException {
    final File dir = db.getDirectory();
    final String logPrefix;
    if (request instanceof HttpServletRequest) {
        HttpServletRequest req = (HttpServletRequest) request;
        logPrefix = "create(" + req.getMethod() + ")[" + req.getRequestURI() + "][" + req.getQueryString()
                + "]";
    } else {// w ww.  ja  v a  2 s . c  om
        logPrefix = "create(" + dir.getAbsolutePath() + ")";
    }
    if (logger.isDebugEnabled()) {
        logger.debug(logPrefix + ": " + dir.getAbsolutePath());
    }

    UploadPack up = new UploadPack(db) {
        @Override
        @SuppressWarnings("synthetic-access")
        public void upload(InputStream input, OutputStream output, OutputStream messages) throws IOException {
            InputStream effIn = input;
            OutputStream effOut = output, effMessages = messages;
            if (logger.isTraceEnabled()) {
                LineLevelAppender inputAppender = new LineLevelAppender() {
                    @Override
                    public void writeLineData(CharSequence lineData) throws IOException {
                        logger.trace(logPrefix + " upload(C): " + lineData);
                    }

                    @Override
                    public boolean isWriteEnabled() {
                        return true;
                    }
                };
                effIn = new TeeInputStream(effIn, new HexDumpOutputStream(inputAppender), true);

                LineLevelAppender outputAppender = new LineLevelAppender() {
                    @Override
                    public void writeLineData(CharSequence lineData) throws IOException {
                        logger.trace(logPrefix + " upload(S): " + lineData);
                    }

                    @Override
                    public boolean isWriteEnabled() {
                        return true;
                    }
                };
                effOut = new TeeOutputStream(effOut, new HexDumpOutputStream(outputAppender));

                if (effMessages != null) {
                    LineLevelAppender messagesAppender = new LineLevelAppender() {
                        @Override
                        public void writeLineData(CharSequence lineData) throws IOException {
                            logger.trace(logPrefix + " upload(M): " + lineData);
                        }

                        @Override
                        public boolean isWriteEnabled() {
                            return true;
                        }
                    };
                    // TODO review the decision to use an AsciiLineOutputStream here
                    effMessages = new TeeOutputStream(effMessages, new AsciiLineOutputStream(messagesAppender));
                }
            }

            super.upload(effIn, effOut, effMessages);
        }

        @Override
        @SuppressWarnings("synthetic-access")
        public void sendAdvertisedRefs(RefAdvertiser adv) throws IOException, ServiceMayNotContinueException {
            RefAdvertiser effAdv = adv;
            if (logger.isTraceEnabled() && (adv instanceof PacketLineOutRefAdvertiser)) {
                PacketLineOut pckOut = (PacketLineOut) ReflectionUtils.getField(pckOutField, adv);
                effAdv = new PacketLineOutRefAdvertiser(pckOut) {
                    private final PacketLineOut pckLog = new PacketLineOut( // TODO review the decision to use an AsciiLineOutputStream here
                            new AsciiLineOutputStream(new LineLevelAppender() {
                                @Override
                                public void writeLineData(CharSequence lineData) throws IOException {
                                    logger.trace(logPrefix + " S: " + lineData);
                                }

                                @Override
                                public boolean isWriteEnabled() {
                                    return true;
                                }
                            }));

                    @Override
                    protected void writeOne(CharSequence line) throws IOException {
                        String s = line.toString();
                        super.writeOne(s);
                        pckLog.writeString(s);
                    }

                    @Override
                    protected void end() throws IOException {
                        super.end();
                        pckLog.end();
                    }
                };
            }

            super.sendAdvertisedRefs(effAdv);
        }
    };
    up.setTimeout(uploadTimeoutValue);
    return up;
}

From source file:net.community.chest.gitcloud.facade.frontend.git.GitController.java

private CloseableHttpResponse transferPostedData(HttpEntityEnclosingRequestBase postRequest,
        final HttpServletRequest req) throws IOException {
    InputStream postData = req.getInputStream();
    try {/*from  www  .j  a v  a  2  s  .c  om*/
        if (logger.isTraceEnabled()) {
            LineLevelAppender appender = new LineLevelAppender() {
                @Override
                @SuppressWarnings("synthetic-access")
                public void writeLineData(CharSequence lineData) throws IOException {
                    logger.trace("transferPostedData(" + req.getMethod() + ")[" + req.getRequestURI() + "]["
                            + req.getQueryString() + "] C: " + lineData);
                }

                @Override
                public boolean isWriteEnabled() {
                    return true;
                }
            };
            postData = new TeeInputStream(postData, new HexDumpOutputStream(appender), true);
        }
        postRequest.setEntity(new InputStreamEntity(postData));
        return client.execute(postRequest);
    } finally {
        postData.close();
    }
}

From source file:net.community.chest.gitcloud.facade.frontend.git.GitController.java

private void transferBackendResponse(final HttpServletRequest req, HttpEntity rspEntity,
        HttpServletResponse rsp) throws IOException {
    final String method = req.getMethod();
    OutputStream rspTarget = rsp.getOutputStream();
    try {/*  ww  w .j a  v a2  s  .  com*/
        if (logger.isTraceEnabled()) {
            LineLevelAppender appender = new LineLevelAppender() {
                @Override
                @SuppressWarnings("synthetic-access")
                public void writeLineData(CharSequence lineData) throws IOException {
                    logger.trace("transferBackendResponse(" + method + ")[" + req.getRequestURI() + "]["
                            + req.getQueryString() + "]" + " S: " + lineData);
                }

                @Override
                public boolean isWriteEnabled() {
                    return true;
                }
            };
            rspTarget = new TeeOutputStream(rspTarget, new HexDumpOutputStream(appender));
        }

        rspEntity.writeTo(rspTarget);
    } finally {
        rspTarget.close();
    }
}