org.eclipse.californium.core.Utils Java Examples
The following examples show how to use
org.eclipse.californium.core.Utils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CoapTestBase.java From hono with Eclipse Public License 2.0 | 6 votes |
/** * Gets a handler for CoAP responses. * * @param responseHandler The handler to invoke with the outcome of the request. the handler will be invoked with a * succeeded result if the response contains the expected code. Otherwise it will be invoked with a * result that is failed with a {@link CoapResultException}. * @param expectedStatusCode The status code that is expected in the response. * @return The handler. */ protected final CoapHandler getHandler(final Handler<AsyncResult<OptionSet>> responseHandler, final ResponseCode expectedStatusCode) { return new CoapHandler() { @Override public void onLoad(final CoapResponse response) { if (response.getCode() == expectedStatusCode) { logger.debug("=> received {}", Utils.prettyPrint(response)); responseHandler.handle(Future.succeededFuture(response.getOptions())); } else { logger.warn("expected {} => received {}", expectedStatusCode, Utils.prettyPrint(response)); responseHandler.handle(Future.failedFuture( new CoapResultException(toHttpStatusCode(response.getCode()), response.getResponseText()))); } } @Override public void onError() { responseHandler .handle(Future.failedFuture(new CoapResultException(HttpURLConnection.HTTP_UNAVAILABLE))); } }; }
Example #2
Source File: Message.java From SI with BSD 2-Clause "Simplified" License | 5 votes |
public String getPayloadTracingString() { if (null == payload || 0 == payload.length) return "no payload"; boolean text = true; for (byte b:payload) { if (' ' > b) { switch(b) { case '\t': case '\n': case '\r': continue; } text = false; break; } } if (text) { CharsetDecoder decoder = CoAP.UTF8_CHARSET.newDecoder(); decoder.onMalformedInput(CodingErrorAction.REPORT); decoder.onUnmappableCharacter(CodingErrorAction.REPORT); ByteBuffer in = ByteBuffer.wrap(payload); CharBuffer out = CharBuffer.allocate(24); CoderResult result = decoder.decode(in, out, true); decoder.flush(out); out.flip(); if (CoderResult.OVERFLOW == result) { return "\"" + out + "\".. " + payload.length + " bytes"; } else if (!result.isError()){ return "\"" + out + "\"" ; } } return Utils.toHexText(payload, 256); }
Example #3
Source File: OptionSet.java From SI with BSD 2-Clause "Simplified" License | 5 votes |
/** * Adds an ETag to the If-Match options. * A byte array of size 0 adds an empty If-Match option, * which checks for existence of the targeted resource. * Returns the current OptionSet object for a fluent API. * @param etag the If-Match ETag to add * @return this OptionSet */ public OptionSet addIfMatch(byte[] etag) { if (etag==null) throw new IllegalArgumentException("If-Match option must not be null"); if (etag.length > 8) throw new IllegalArgumentException("If-Match option must be smaller or equal to 8 bytes: "+Utils.toHexString(etag)); getIfMatch().add(etag); return this; }
Example #4
Source File: Message.java From SI with BSD 2-Clause "Simplified" License | 5 votes |
public String getPayloadTracingString() { if (null == payload || 0 == payload.length) return "no payload"; boolean text = true; for (byte b:payload) { if (' ' > b) { switch(b) { case '\t': case '\n': case '\r': continue; } text = false; break; } } if (text) { CharsetDecoder decoder = CoAP.UTF8_CHARSET.newDecoder(); decoder.onMalformedInput(CodingErrorAction.REPORT); decoder.onUnmappableCharacter(CodingErrorAction.REPORT); ByteBuffer in = ByteBuffer.wrap(payload); CharBuffer out = CharBuffer.allocate(24); CoderResult result = decoder.decode(in, out, true); decoder.flush(out); out.flip(); if (CoderResult.OVERFLOW == result) { return "\"" + out + "\".. " + payload.length + " bytes"; } else if (!result.isError()){ return "\"" + out + "\"" ; } } return Utils.toHexText(payload, 256); }
Example #5
Source File: OptionSet.java From SI with BSD 2-Clause "Simplified" License | 5 votes |
/** * Adds an ETag to the If-Match options. * A byte array of size 0 adds an empty If-Match option, * which checks for existence of the targeted resource. * Returns the current OptionSet object for a fluent API. * @param etag the If-Match ETag to add * @return this OptionSet */ public OptionSet addIfMatch(byte[] etag) { if (etag==null) throw new IllegalArgumentException("If-Match option must not be null"); if (etag.length > 8) throw new IllegalArgumentException("If-Match option must be smaller or equal to 8 bytes: "+Utils.toHexString(etag)); getIfMatch().add(etag); return this; }
Example #6
Source File: Exchange.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
@Override public String toString() { return "KeyMID["+MID+" for "+Utils.toHexString(address)+":"+port+"]"; }
Example #7
Source File: Exchange.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
@Override public String toString() { return "KeyToken["+Utils.toHexString(token)+"]"; }
Example #8
Source File: Exchange.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
@Override public String toString() { return "KeyUri["+uri+" for "+Utils.toHexString(address)+":"+port+"]"; }
Example #9
Source File: Exchange.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
@Override public String toString() { return "KeyMID["+MID+" for "+Utils.toHexString(address)+":"+port+"]"; }
Example #10
Source File: Exchange.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
@Override public String toString() { return "KeyToken["+Utils.toHexString(token)+"]"; }
Example #11
Source File: Exchange.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
@Override public String toString() { return "KeyUri["+uri+" for "+Utils.toHexString(address)+":"+port+"]"; }