use of com.codename1.io.URL in project CodenameOne by codenameone.
the class HTTPUtil method requiresUpdate.
public static boolean requiresUpdate(URL u, File destFile, boolean forceCheck) throws IOException {
// https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download
if (destFile.exists() && "github.com".equals(u.getHost()) && u.getPath().contains("/releases/download/")) {
logger.fine("Github release assets should not require updating.");
return false;
}
if (!forceCheck && getExpiryDate(destFile) >= System.currentTimeMillis()) {
return false;
}
File etagFile = new File(destFile.getParentFile(), destFile.getName() + ".etag");
if (destFile.exists() && etagFile.exists()) {
String etag;
try (InputStream is = new FileInputStream(etagFile)) {
etag = readToString(is).trim();
}
DownloadResponse resp = new DownloadResponse();
if (doesETagMatch(resp, u, etag)) {
saveExpires(resp, destFile);
return false;
}
saveExpires(resp, destFile);
}
return true;
}
use of com.codename1.io.URL in project CodenameOne by codenameone.
the class WebPushTest method push.
@Override
public void push(String value) {
PushContent data = PushContent.get();
if (data != null) {
System.out.println("Image URL: " + data.getImageUrl());
System.out.println("Category: " + data.getCategory());
System.out.println("Action: " + data.getActionId());
System.out.println("Text Response: " + data.getTextResponse());
} else {
System.out.println("PushContent is null");
}
System.out.println("Push " + value);
Display.getInstance().callSerially(() -> {
Dialog.show("Push received", value, "OK", null);
});
}
use of com.codename1.io.URL in project CodenameOne by codenameone.
the class WebSocketReconnectTest method start.
public void start() {
if (current != null) {
current.show();
return;
}
String uniqueId = "1234";
Form hi = new Form("WebSocket Test", BoxLayout.y());
hi.getToolbar().addCommandToRightBar("Start Test", null, evt -> {
hi.removeAll();
String url = "wss://weblite.ca/ws/cn1-websocket-demo/chat";
if (!"HTML5".equals(CN.getPlatformName())) {
url = "wss://chat.mydissent.net/wsMsg";
}
WebSocket.setDebugLoggingEnabled(true);
final WebSocket sock = new WebSocket(url) {
@Override
protected void onOpen() {
Log.p("WebSocket onOpen - Sending uniqueId: " + uniqueId);
hi.add("WebSocket onOpen - Sending uniqueId: " + uniqueId);
hi.animateLayout(400);
send(uniqueId);
}
@Override
protected void onClose(int statusCode, String reason) {
Log.p("WebSocket onClose");
hi.add("WebSocket onClose");
hi.animateLayout(400);
}
@Override
protected void onMessage(String message) {
Log.p("WebSocket onMessage: " + message);
hi.add(new SpanLabel("WebSocket onMessage: " + message));
hi.animateLayout(400);
}
@Override
protected void onMessage(byte[] message) {
Log.p("WebSocket onMessage (byte[]): " + message.toString());
}
@Override
protected void onError(Exception ex) {
Log.e(ex);
hi.add(new SpanLabel("WebSocket onError:\n" + ex.getMessage()));
}
};
sock.connect();
sock.autoReconnect(5000);
UITimer.timer(5000, false, hi, () -> {
sock.close();
});
});
hi.show();
}
use of com.codename1.io.URL in project CodenameOne by codenameone.
the class CodenameOneImplementation method downloadImageToFileSystem.
/**
* Downloads an image to file system. This will *not* first check to see if the file exists already.
* It will download and overwrite any existing image at the provided location.
*
* <p>Some platforms may override this method to use platform-level caching. E.g. Javascript will use
* the browser cache for downloading the image.</p>
*
* @param url The URL of the image to download.
* @param fileName The storage key to be used to store the image.
* @param onSuccess Callback on success. Will be executed on EDT.
* @param onFail Callback on failure. Will be executed on EDT.
*/
public void downloadImageToFileSystem(String url, String fileName, SuccessCallback<Image> onSuccess, FailureCallback<Image> onFail) {
ConnectionRequest cr = new ConnectionRequest();
cr.setPost(false);
cr.setFailSilently(true);
cr.setReadResponseForErrors(false);
cr.setDuplicateSupported(true);
cr.setUrl(url);
cr.downloadImageToFileSystem(fileName, onSuccess, onFail);
}
use of com.codename1.io.URL in project CodenameOne by codenameone.
the class CodenameOneImplementation method downloadImageToStorage.
/**
* Downloads an image to storage. This will *not* first check to see if the image is located in storage
* already. It will download and overwrite any existing image at the provided location.
*
* <p>Some platforms may override this method to use platform-level caching. E.g. Javascript will use
* the browser cache for downloading the image.</p>
*
* @param url The URL of the image to download.
* @param fileName The storage key to be used to store the image.
* @param onSuccess Callback on success. Will be executed on EDT.
* @param onFail Callback on failure. Will be executed on EDT.
*/
public void downloadImageToStorage(String url, String fileName, SuccessCallback<Image> onSuccess, FailureCallback<Image> onFail) {
ConnectionRequest cr = new ConnectionRequest();
cr.setPost(false);
cr.setFailSilently(true);
cr.setReadResponseForErrors(false);
cr.setDuplicateSupported(true);
cr.setUrl(url);
cr.downloadImageToStorage(fileName, onSuccess, onFail);
}
Aggregations