Example usage for org.apache.http.util Args notNull

List of usage examples for org.apache.http.util Args notNull

Introduction

In this page you can find the example usage for org.apache.http.util Args notNull.

Prototype

public static <T> T notNull(T t, String str) 

Source Link

Usage

From source file:com.ok2c.lightmtp.impl.protocol.SendRsetCodec.java

@Override
public void consumeData(final IOSession iosession, final ClientState sessionState)
        throws IOException, SMTPProtocolException {
    Args.notNull(iosession, "IO session");
    Args.notNull(sessionState, "Session state");

    SessionInputBuffer buf = this.iobuffers.getInbuf();

    int bytesRead = buf.fill(iosession.channel());
    SMTPReply reply = this.parser.parse(buf, bytesRead == -1);

    if (reply != null) {
        switch (this.codecState) {
        case RSET_RESPONSE_EXPECTED:
            sessionState.reset(null);/*w  w w  . ja v a2s. c  o  m*/
            sessionState.setReply(reply);
            this.codecState = CodecState.COMPLETED;
            break;
        default:
            throw new SMTPProtocolException("Unexpected reply: " + reply);
        }
    }
}

From source file:com.ok2c.lightmtp.util.InetAddressRangeParser.java

public List<InetAddressRange> parseAll(final CharArrayBuffer buffer, final ParserCursor cursor,
        final char[] delimiters) throws ParseException, UnknownHostException {

    Args.notNull(buffer, "Char array buffer");
    Args.notNull(cursor, "Parser cursor");

    char[] delims = delimiters != null ? delimiters : COMMA;

    List<InetAddressRange> ranges = new ArrayList<InetAddressRange>();
    while (!cursor.atEnd()) {
        ranges.add(parse(buffer, cursor, delims));
        int pos = cursor.getPos();
        if (pos < cursor.getUpperBound() && isOneOf(buffer.charAt(pos), delims)) {
            cursor.updatePos(pos + 1);/*from   w  w  w. j  a  v  a  2  s  .c o m*/
        }
    }
    return ranges;
}

From source file:com.ok2c.lightmtp.impl.protocol.PipeliningSendEnvelopCodec.java

@Override
public void produceData(final IOSession iosession, final ClientState sessionState)
        throws IOException, SMTPProtocolException {
    Args.notNull(iosession, "IO session");
    Args.notNull(sessionState, "Session state");
    if (sessionState.getRequest() == null) {
        if (sessionState.isTerminated()) {
            this.codecState = CodecState.COMPLETED;
        }/* ww w  .j a  v  a2  s .  c om*/
        return;
    }

    SessionOutputBuffer buf = this.iobuffers.getOutbuf();
    DeliveryRequest request = sessionState.getRequest();

    switch (this.codecState) {
    case MAIL_REQUEST_READY:
        SMTPCommand mailFrom = new SMTPCommand("MAIL", "FROM:<" + request.getSender() + ">");
        this.writer.write(mailFrom, buf);

        this.recipients.addAll(request.getRecipients());

        for (String recipient : request.getRecipients()) {
            SMTPCommand rcptTo = new SMTPCommand("RCPT", "TO:<" + recipient + ">");
            this.writer.write(rcptTo, buf);
        }
        SMTPCommand data = new SMTPCommand("DATA");
        this.writer.write(data, buf);
        this.codecState = CodecState.MAIL_RESPONSE_EXPECTED;
        break;
    }

    if (buf.hasData()) {
        buf.flush(iosession.channel());
    }
    if (!buf.hasData()) {
        iosession.clearEvent(SelectionKey.OP_WRITE);
    }
}

From source file:com.ok2c.lightmtp.impl.protocol.SimpleSendEnvelopCodec.java

@Override
public void produceData(final IOSession iosession, final ClientState sessionState)
        throws IOException, SMTPProtocolException {
    Args.notNull(iosession, "IO session");
    Args.notNull(sessionState, "Session state");
    if (sessionState.getRequest() == null) {
        if (sessionState.isTerminated()) {
            this.codecState = CodecState.COMPLETED;
        }/*from  ww  w . ja v a 2s  . c  om*/
        return;
    }

    SessionOutputBuffer buf = this.iobuffers.getOutbuf();
    DeliveryRequest request = sessionState.getRequest();

    switch (this.codecState) {
    case MAIL_REQUEST_READY:
        SMTPCommand mailFrom = new SMTPCommand("MAIL", "FROM:<" + request.getSender() + ">");
        this.writer.write(mailFrom, buf);

        this.codecState = CodecState.MAIL_RESPONSE_EXPECTED;
        iosession.setEvent(SelectionKey.OP_READ);
        break;
    case RCPT_REQUEST_READY:
        String recipient = this.recipients.getFirst();

        SMTPCommand rcptTo = new SMTPCommand("RCPT", "TO:<" + recipient + ">");
        this.writer.write(rcptTo, buf);

        this.codecState = CodecState.RCPT_RESPONSE_EXPECTED;
        break;
    case DATA_REQUEST_READY:
        SMTPCommand data = new SMTPCommand("DATA");
        this.writer.write(data, buf);
        this.codecState = CodecState.DATA_RESPONSE_EXPECTED;
        break;
    }

    if (buf.hasData()) {
        buf.flush(iosession.channel());
    }
    if (!buf.hasData()) {
        iosession.clearEvent(SelectionKey.OP_WRITE);
    }
}

From source file:com.ok2c.lightmtp.impl.protocol.SimpleSendHeloCodec.java

@Override
public void consumeData(final IOSession iosession, final ClientState sessionState)
        throws IOException, SMTPProtocolException {
    Args.notNull(iosession, "IO session");
    Args.notNull(sessionState, "Session state");

    SessionInputBuffer buf = this.iobuffers.getInbuf();

    int bytesRead = buf.fill(iosession.channel());
    SMTPReply reply = this.parser.parse(buf, bytesRead == -1);

    if (reply != null) {
        switch (this.codecState) {
        case SERVICE_READY_EXPECTED:
            if (reply.getCode() == SMTPCodes.SERVICE_READY) {
                this.codecState = CodecState.HELO_READY;
                iosession.setEvent(SelectionKey.OP_WRITE);
            } else {
                this.codecState = CodecState.COMPLETED;
                sessionState.setReply(reply);
            }//from   w  w w.  ja  v  a2  s  .co m
            break;
        case HELO_RESPONSE_EXPECTED:
            this.codecState = CodecState.COMPLETED;
            sessionState.setReply(reply);
            break;
        default:
            if (reply.getCode() == SMTPCodes.ERR_TRANS_SERVICE_NOT_AVAILABLE) {
                sessionState.setReply(reply);
                this.codecState = CodecState.COMPLETED;
            } else {
                throw new SMTPProtocolException("Unexpected reply: " + reply);
            }
        }
    } else {
        if (bytesRead == -1 && !sessionState.isTerminated()) {
            throw new UnexpectedEndOfStreamException();
        }
    }
}

From source file:net.dv8tion.jda.core.entities.impl.MemberImpl.java

@Override
public boolean hasPermission(Collection<Permission> permissions) {
    Args.notNull(permissions, "Permission Collection");

    return hasPermission(permissions.toArray(new Permission[permissions.size()]));
}

From source file:gov.ic.geoint.bulleit.apache.UriPatternMatcher.java

/**
 * Looks up an object matching the given request path.
 *
 * @param path the request path//w  w  w. j  a  va 2  s.c  o m
 * @return object or {@code null} if no match is found.
 */
public synchronized T lookup(final String path) {
    Args.notNull(path, "Request path");
    // direct match?
    T obj = this.map.get(path);
    if (obj == null) {
        // pattern match?
        String bestMatch = null;
        for (final String pattern : this.map.keySet()) { //if match not found, and path is relative, go w/ previous match value??
            if (matchUriRequestPattern(pattern, path)) {
                // we have a match. is it any better?
                if (bestMatch == null || (bestMatch.length() < pattern.length())
                        || (bestMatch.length() == pattern.length() && pattern.endsWith("*"))) {
                    obj = this.map.get(pattern);
                    bestMatch = pattern;
                }
            }
        }
        //            //way to handle relative paths
        //            if (obj == null && path.startsWith("/")) {
        //                obj = previousMatch;
        //            }
    }
    //        if (obj != null) {
    //            previousMatch = obj;
    //        }
    return obj;
}

From source file:de.vanita5.twittnuker.util.net.ssl.HostResolvedSSLConnectionSocketFactory.java

public HostResolvedSSLConnectionSocketFactory(final SSLContext sslContext, final String[] supportedProtocols,
        final String[] supportedCipherSuites, final X509HostnameVerifier hostnameVerifier) {
    this(Args.notNull(sslContext, "SSL context").getSocketFactory(), supportedProtocols, supportedCipherSuites,
            hostnameVerifier);//from w w w. j a  v a 2  s  . c  o  m
}

From source file:org.apache.hadoop.gateway.dispatch.InputStreamEntity.java

/**
 * @param instream    input stream//from   w  w w  .ja  v  a2s  .  c o  m
 * @param length      of the input stream, {@code -1} if unknown
 * @param contentType for specifying the {@code Content-Type} header, may be {@code null}
 * @throws IllegalArgumentException if {@code instream} is {@code null}
 */
public InputStreamEntity(final InputStream instream, final long length, final ContentType contentType) {
    super();
    this.content = Args.notNull(instream, "Source input stream");
    this.length = length;
    if (contentType != null) {
        setContentType(contentType.toString());
    }
}