protected void displayResult (Net.Response rsp) { StringBuilder buf = new StringBuilder(); buf.append("Response code: ").append(rsp.responseCode()); buf.append("\n\nHeaders:\n"); for (String header : rsp.headerNames()) { buf.append(header).append(":"); int vv = 0; for (String value : rsp.headers(header)) { if (vv++ > 0) buf.append(","); buf.append(" ").append(value); } buf.append("\n"); } buf.append("\nBody:\n"); String payload = rsp.payloadString(); if (payload.length() > 1024) payload = payload.substring(0, 1024) + "..."; buf.append(payload); displayText(buf.toString()); }
String[] lines = rsp.payloadString().split("[\r\n]+"); String urlPre = "View it at "; for (String line : lines) {
@Override public void init() { Image orange = game.assets.getImage("images/orange.png"); ImageLayer l1 = new ImageLayer(orange); game.rootLayer.addAt(l1.setScale(2).setRotation(FloatMath.PI/8), 50, 50); l1.events().connect(new Mover(l1).listener(game.input)); ImageLayer l2 = new ImageLayer(orange); game.rootLayer.addAt(l2.setScale(1.5f).setRotation(FloatMath.PI/4), 150, 50); l2.events().connect(new Mover(l2).listener(game.input)); Image mdb = game.assets.getRemoteImage("https://www.samskivert.com/images/headshot.jpg"); ImageLayer l3 = new ImageLayer(mdb); game.rootLayer.addAt(l3.setRotation(-FloatMath.PI/4), 50, 150); l3.events().connect(new Mover(l3).listener(game.input)); String l4url = "https://www.samskivert.com/images/2012/12/spellwood-app-icon.png"; game.net.req(l4url).execute().onSuccess(rsp -> { try { Image icon = rsp.payloadImage(new Scale(2)); ImageLayer l4 = new ImageLayer(icon); game.rootLayer.addAt(l4.setRotation(FloatMath.PI/4), 150, 150); l4.events().connect(new Mover(l4).listener(game.input)); } catch (Exception e) { game.log.warn("Failed to decode image: " + e); } }).onFailure(t -> game.log.warn("Failed to load image: " + l4url, t)); }
protected void displayResult (Net.Response rsp) { StringBuilder buf = new StringBuilder(); buf.append("Response code: ").append(rsp.responseCode()); buf.append("\n\nHeaders:\n"); for (String header : rsp.headerNames()) { buf.append(header).append(":"); int vv = 0; for (String value : rsp.headers(header)) { if (vv++ > 0) buf.append(","); buf.append(" ").append(value); } buf.append("\n"); } buf.append("\nBody:\n"); String payload = rsp.payloadString(); if (payload.length() > 1024) payload = payload.substring(0, 1024) + "..."; buf.append(payload); displayText(buf.toString()); }
public String apply (Response rsp) { return rsp.payloadString(); } };
public String apply (Response rsp) { return rsp.payloadString(); } };
/** Returns the names of all headers returned by the server. */ public Iterable<String> headerNames() { return headers().keySet(); }
/** Returns the names of all headers returned by the server. */ public Iterable<String> headerNames() { return headers().keySet(); }
public void onSuccess (Net.Response rsp) { image.setImage(new UIImage(new NSData(rsp.payload())), Scale.ONE); } public void onFailure (Throwable cause) {
/** Returns the value of all headers with the specified name, or the empty list. * <p><em>NOTE:</em> on the iOS backend, repeated headers will be coalesced into a single * header separated by commas. This sucks but we can't "undo" the coalescing without breaking * otherwise normal headers that happent to contain commas. Complain to Apple.</p> */ public List<String> headers(String name) { List<String> values = headers().get(name); return values == null ? Collections.<String>emptyList() : values; }
/** Returns the value of the header with the specified name, or null. If there are multiple * response headers with this name, one will be chosen using an undefined algorithm. */ public String header(String name) { List<String> values = headers().get(name); return (values == null) ? null : values.get(0); }
private Map<String,List<String>> headers() { if (headersMap == null) { headersMap = extractHeaders(); } return headersMap; } }
/** Returns the value of the header with the specified name, or null. If there are multiple * response headers with this name, one will be chosen using an undefined algorithm. */ public String header(String name) { List<String> values = headers().get(name); return (values == null) ? null : values.get(0); }
/** Returns the value of all headers with the specified name, or the empty list. * <p><em>NOTE:</em> on the iOS backend, repeated headers will be coalesced into a single * header separated by commas. This sucks but we can't "undo" the coalescing without breaking * otherwise normal headers that happent to contain commas. Complain to Apple.</p> */ public List<String> headers(String name) { List<String> values = headers().get(name); return values == null ? Collections.<String>emptyList() : values; }
private Map<String,List<String>> headers() { if (headersMap == null) { headersMap = extractHeaders(); } return headersMap; } }