Example usage for org.eclipse.jgit.transport UploadPack getMessageOutputStream

List of usage examples for org.eclipse.jgit.transport UploadPack getMessageOutputStream

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport UploadPack getMessageOutputStream.

Prototype

public OutputStream getMessageOutputStream() 

Source Link

Document

Get an underlying stream for sending messages to the client

Usage

From source file:com.googlesource.gerrit.plugins.motd.DisplayMotd.java

License:Apache License

@Override
public void onPreUpload(Repository repository, Project project, String remote, UploadPack up,
        Collection<? extends ObjectId> wants, Collection<? extends ObjectId> haves) throws ValidationException {
    PrintWriter pw = new PrintWriter(up.getMessageOutputStream());

    if (config.getMotd() != null) {
        pw.print(format(config.getMotd()));
        pw.print("\n");
    }//ww  w.  j  av a 2  s.com

    try {
        String inet = InetAddress.getByName(remote).getHostAddress();
        for (Subnet m : config.getSubnets()) {
            if (m.isInRange(inet) && m.getMotd() != null) {
                pw.print(format(m.getMotd()));
                pw.print("\n");
                break;
            }
        }
    } catch (UnknownHostException e) {
        // Couldn't look up the hostname; this is non-fatal
    }
    pw.flush();
}