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:org.zalando.stups.tokens.util.Objects.java

public static <T> T notNull(String name, T object) {
    return Args.notNull(object, name);
}

From source file:de.hsos.ecs.richwps.wpsmonitor.util.Validate.java

/**
 * Checks if a Parameter is null./*  w w w. j  a  v  a  2 s .  c  o  m*/
 *
 * @param <T> Return type
 * @param var Check if null
 * @param name Outputname for exception message
 * @return T
 */
public static <T> T notNull(final T var, final String name) {
    Args.notNull(var, name);

    return var;
}

From source file:net.dv8tion.jda.core.utils.IOUtil.java

/**
 * Used as an alternate to Java's nio Files.readAllBytes.
 * <p>//ww  w  .j  a  v a 2  s  . c  om
 * This customized version for File is provide (instead of just using {@link #readFully(java.io.InputStream)} with a FileInputStream)
 * because
 * with a File we can determine the total size of the array and do not need to have a buffer. This results
 * in a memory footprint that is half the size of {@link #readFully(java.io.InputStream)}
 * <p>
 * Code provided from <a href="http://stackoverflow.com/a/6276139">http://stackoverflow.com/a/6276139</a>
 *
 * @param file
 *          The file from which we should retrieve the bytes from
 * @return
 *      A byte[] containing all of the file's data
 * @throws IOException
 *      Thrown if there is a problem while reading the file.
 */
public static byte[] readFully(File file) throws IOException {
    Args.notNull(file, "File");
    Args.check(file.exists(), "Provided file does not exist!");

    try (InputStream is = new FileInputStream(file)) {
        // Get the size of the file
        long length = file.length();

        // You cannot create an array using a long type.
        // It needs to be an int type.
        // Before converting to an int type, check
        // to ensure that file is not larger than Integer.MAX_VALUE.
        if (length > Integer.MAX_VALUE) {
            throw new IOException("Cannot read the file into memory completely due to it being too large!");
            // File is too large
        }

        // Create the byte array to hold the data
        byte[] bytes = new byte[(int) length];

        // Read in the bytes
        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
            offset += numRead;
        }

        // Ensure all the bytes have been read in
        if (offset < bytes.length) {
            throw new IOException("Could not completely read file " + file.getName());
        }

        // Close the input stream and return bytes
        is.close();
        return bytes;
    }
}

From source file:com.ok2c.lightmtp.protocol.RcptResult.java

public RcptResult(final SMTPReply reply, final String recipient) {
    super();//from   w w  w.j  a v  a  2  s.co  m
    Args.notNull(reply, "SMTP reply");
    Args.notNull(recipient, "Recipient");
    this.reply = reply;
    this.recipient = recipient;
}

From source file:org.zalando.stups.tokens.FileSupplier.java

FileSupplier(final File file) {
    this.file = Args.notNull(file, "file");
    this.filename = null;
}

From source file:com.ok2c.lightmtp.SMTPCommand.java

public SMTPCommand(final String code, final String argument, final List<String> params) {
    super();//from   ww w .  j  a v  a  2s  . c  o m
    Args.notNull(code, "Code");
    this.verb = code;
    this.argument = argument;
    if (params == null || params.isEmpty()) {
        this.params = Collections.emptyList();
    } else {
        this.params = Collections.unmodifiableList(new ArrayList<String>(params));
    }
}

From source file:com.ok2c.lightmtp.protocol.BasicDeliveryResult.java

public BasicDeliveryResult(final SMTPReply reply, final List<RcptResult> rcptFailures) {
    super();/*from  ww w . jav  a2 s  .co m*/
    Args.notNull(reply, "SMTP reply");
    this.reply = reply;
    ArrayList<RcptResult> list = new ArrayList<RcptResult>();
    if (rcptFailures != null) {
        list.addAll(rcptFailures);
    }
    this.failures = Collections.unmodifiableList(list);
}

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

public InetAddressRange(final InetAddress address, final int mask) {
    super();//from ww w  .  java  2 s  .c o  m
    Args.notNull(address, "Address");
    if (mask < 0) {
        throw new IllegalArgumentException("Address mask may not be negative");
    }
    this.address = address;
    this.mask = mask;

    byte[] addr = address.getAddress();
    BigInteger bigint = new BigInteger(addr);
    int shiftBy = 0;
    if (mask > 0) {
        if (addr.length == 4) {
            shiftBy = 32 - mask;
        } else if (addr.length == 16) {
            shiftBy = 128 - mask;
        } else {
            throw new IllegalArgumentException("Unsupported address: " + address);
        }
    }
    if (shiftBy > 0) {
        bigint = bigint.shiftRight(shiftBy);
    }
    this.bigint = bigint;
    this.shiftBy = shiftBy;
}

From source file:net.dv8tion.jda.core.entities.Icon.java

/**
 * Creates an {@link Icon Icon} with the specified {@link java.io.File File}.<br>
 * We here read the specified File and forward the retrieved byte data to {@link #from(byte[])}.
 *
 * @param file/*  w  w  w.  ja  va 2s  .co m*/
 *      An existing, not-null file.
 * @return
 *      An Icon instance representing the specified File
 * @throws IllegalArgumentException
 *      if the provided file is either null or does not exist
 * @throws IOException
 *      if there is a problem while reading the file.
 * @see net.dv8tion.jda.core.utils.IOUtil#readFully(File)
 */
public static Icon from(File file) throws IOException {
    Args.notNull(file, "Provided File");
    Args.check(file.exists(), "Provided file does not exist!");

    return from(IOUtil.readFully(file));
}

From source file:com.ok2c.lightmtp.protocol.BasicDeliveryRequest.java

public BasicDeliveryRequest(final String sender, final List<String> recipients,
        final SMTPContent<ReadableByteChannel> content) {
    super();/*from ww w.  ja v a2s. c  o  m*/
    Args.notNull(sender, "Sender");
    if (recipients == null || recipients.isEmpty()) {
        throw new IllegalArgumentException("List of recipients may not be null or empty");
    }
    Args.notNull(content, "Delivery content");
    this.sender = sender;
    this.recipients = Collections.unmodifiableList(new ArrayList<String>(recipients));
    this.content = content;
}