List of usage examples for org.apache.http.util Args notNull
public static <T> T notNull(T t, String str)
From source file:com.ok2c.lightmtp.impl.protocol.PipeliningReceiveEnvelopCodec.java
public PipeliningReceiveEnvelopCodec(final SMTPBuffers iobuffers, final ProtocolHandler<ServerState> commandHandler) { super();//from w ww . j a v a2 s. com Args.notNull(iobuffers, "IO buffers"); Args.notNull(commandHandler, "Command handler"); this.iobuffers = iobuffers; this.commandHandler = commandHandler; this.parser = new SMTPCommandParser(); this.writer = new SMTPReplyWriter(true); this.pendingActions = new LinkedList<Action<ServerState>>(); this.completed = false; }
From source file:com.ok2c.lightmtp.impl.protocol.LocalServerSessionFactory.java
public LocalServerSessionFactory(final File workingDir, final UniqueIdGenerator idgenerator, final RemoteAddressValidator addressValidator, final EnvelopValidator validator, final DeliveryHandler deliveryHandler) { super();/*from w w w . j a v a 2 s . c o m*/ Args.notNull(workingDir, "Working dir"); Args.notNull(idgenerator, "Id generator"); Args.notNull(validator, "Envelop validator"); Args.notNull(deliveryHandler, "Delivery handler"); this.workingDir = workingDir; this.idgenerator = idgenerator; this.addressValidator = addressValidator; this.validator = validator; this.deliveryHandler = deliveryHandler; }
From source file:com.wudaosoft.net.httpclient.FileResponseHandler.java
@Override public File handleResponse(HttpResponse response) throws ClientProtocolException, IOException { int status = response.getStatusLine().getStatusCode(); if (status != 200) { throw new ClientProtocolException("Unexpected response status: " + status); }/*from w ww. j a v a 2 s . co m*/ HttpEntity entity = response.getEntity(); if (entity == null || !entity.isStreaming()) { throw new ClientProtocolException("Response contains no content"); } File tempFile = null; if (this.file != null) { tempFile = this.file; } else if (this.dir != null) { Header contentDisposition = response.getLastHeader("Content-disposition"); String filename = contentDisposition.getValue().split(";")[1].split("=")[1].replace("\"", ""); tempFile = new File(this.dir, filename); } Args.notNull(tempFile, "file"); Args.check(tempFile.canWrite(), "file must be writeable"); InputStream inputStream = entity.getContent(); FileOutputStream outputStream = new FileOutputStream(tempFile); try { byte[] buff = new byte[4096]; int size = -1; while ((size = inputStream.read(buff)) != -1) { outputStream.write(buff, 0, size); } outputStream.flush(); return tempFile; } finally { try { outputStream.close(); } catch (IOException e) { } } }
From source file:net.dv8tion.jda.core.entities.Icon.java
/** * Creates an {@link Icon Icon} with the specified image data. * * @param data/* ww w . ja v a 2 s. co m*/ * not-null image data bytes. * @return * An Icon instance representing the specified image data * @throws IllegalArgumentException * if the provided data is null */ public static Icon from(byte[] data) { Args.notNull(data, "Provided byte[]"); String encoding = StringUtils.newStringUtf8(Base64.getEncoder().encode(data)); return new Icon(encoding); }
From source file:com.ok2c.lightmtp.impl.protocol.ServerSessionFactory.java
public ServerSessionFactory(final File workingDir, final UniqueIdGenerator idgenerator, final RemoteAddressValidator addressValidator, final EnvelopValidator validator, final DeliveryHandler deliveryHandler) { super();//from w ww .j a v a 2 s . c o m Args.notNull(workingDir, "Working dir"); Args.notNull(idgenerator, "Id generator"); Args.notNull(validator, "Envelop validator"); Args.notNull(deliveryHandler, "Delivery handler"); this.workingDir = workingDir; this.idgenerator = idgenerator; this.addressValidator = addressValidator; this.validator = validator; this.deliveryHandler = deliveryHandler; }
From source file:com.ok2c.lightmtp.impl.protocol.SendQuitCodec.java
@Override public void produceData(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); SessionOutputBuffer buf = this.iobuffers.getOutbuf(); switch (this.codecState) { case QUIT_READY: SMTPCommand quit = new SMTPCommand("QUIT"); this.writer.write(quit, buf); this.codecState = CodecState.QUIT_RESPONSE_EXPECTED; break;// w w w. ja v a 2 s.c o m } if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData()) { iosession.clearEvent(SelectionKey.OP_WRITE); } }
From source file:com.ok2c.lightmtp.impl.protocol.SendRsetCodec.java
@Override public void produceData(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); SessionOutputBuffer buf = this.iobuffers.getOutbuf(); switch (this.codecState) { case RSET_READY: SMTPCommand quit = new SMTPCommand("RSET"); this.writer.write(quit, buf); this.codecState = CodecState.RSET_RESPONSE_EXPECTED; break;//from w ww . j av a 2s. co m } if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData()) { iosession.clearEvent(SelectionKey.OP_WRITE); } }
From source file:net.dv8tion.jda.core.entities.impl.PrivateChannelImpl.java
@Override public RestAction<Message> sendMessage(Message msg) { Args.notNull(msg, "Message"); Route.CompiledRoute route = Route.Messages.SEND_MESSAGE.compile(getId()); JSONObject json = ((MessageImpl) msg).toJSONObject(); return new RestAction<Message>(getJDA(), route, json) { @Override// w ww .ja v a 2s. co m protected void handleResponse(Response response, Request request) { if (response.isOk()) { Message m = EntityBuilder.get(getJDA()).createMessage(response.getObject()); request.onSuccess(m); } else { request.onFailure(response); } } }; }
From source file:org.fao.geonet.utils.nio.PathHttpEntity.java
public void writeTo(final OutputStream outstream) throws IOException { Args.notNull(outstream, "Output stream"); try (final InputStream instream = IO.newInputStream(this.file)) { final byte[] tmp = new byte[OUTPUT_BUFFER_SIZE]; int l;/* w w w . j a v a 2s . c om*/ while ((l = instream.read(tmp)) != -1) { outstream.write(tmp, 0, l); } outstream.flush(); } }
From source file:com.ok2c.lightmtp.impl.protocol.SimpleSendHeloCodec.java
@Override public void produceData(final IOSession iosession, final ClientState sessionState) throws IOException, SMTPProtocolException { Args.notNull(iosession, "IO session"); Args.notNull(sessionState, "Session state"); SessionOutputBuffer buf = this.iobuffers.getOutbuf(); switch (this.codecState) { case HELO_READY: SMTPCommand helo = new SMTPCommand("HELO", AddressUtils.resolveLocalDomain(iosession.getLocalAddress())); this.writer.write(helo, buf); this.codecState = CodecState.HELO_RESPONSE_EXPECTED; break;//from w ww . j av a2 s . c o m } if (buf.hasData()) { buf.flush(iosession.channel()); } if (!buf.hasData()) { iosession.clearEvent(SelectionKey.OP_WRITE); } }