List of usage examples for com.squareup.okhttp HttpUrl parse
public static HttpUrl parse(String url)
From source file:net.yatomiya.e4.services.image.ImageService.java
License:Open Source License
public ImageEntry getEntry(String url) { HttpUrl httpUrl = HttpUrl.parse(url); if (httpUrl == null) throw new IllegalArgumentException(url + " is invalid."); return getEntry(httpUrl); }
From source file:net.yatomiya.e4.services.image.StorageManager.java
License:Open Source License
public EntryData getEntryData(String url) { EntryData data = CUtils.findFirst(pData.entryList, d -> url.equals(d.url)); if (data == null) { String filename = StringUtils.digest(url); String ext = StringUtils.getExtension(HttpUtils.getPathName(HttpUrl.parse(url))); if (!JUtils.isEmpty(ext)) filename += "." + ext; data = new EntryData(url, filename); pData.entryList.add(data);// ww w . ja v a2 s . c om } return data; }
From source file:net.yatomiya.e4.services.image.StorageManager.java
License:Open Source License
public void cleanup() { Map<HttpUrl, ImageEntry> entryMap = service.getEntryMap(); List<EntryData> list = pData.entryList.stream().filter(d -> entryMap.get(HttpUrl.parse(d.url)) == null). // exclude entry in use sorted((d1, d2) -> JUtils.sign(d1.lastImageAccessTime - d2.lastImageAccessTime)). // recently used first collect(Collectors.toList()); long total = 0; for (int i = 0; i < list.size(); i++) { EntryData d = list.get(i);//from w w w . j av a2 s . c om if (d.fileByteSize < 0) { pData.entryList.remove(d); } else { if (i > pData.maxFileCount || total > pData.maxStorageByteSize) { File file = getImageStorageFile(d.filename); file.delete(); pData.entryList.remove(d); } total += d.fileByteSize; } } }
From source file:net.yatomiya.e4.util.HttpUtils.java
License:Open Source License
public static URL toURL(String str) { try {/*from ww w . ja v a 2 s.com*/ // HttpUrl checks url more strictly than java.net.URL. HttpUrl hurl = HttpUrl.parse(str); URL url = hurl.url(); return url; } catch (Exception e) { return null; } }
From source file:net.yatomiya.e4.util.HttpUtils.java
License:Open Source License
public static String getHost(String url) { try {/*from www.j a va2s . c o m*/ HttpUrl hurl = HttpUrl.parse(url); return hurl.host(); } catch (Throwable e) { return null; } }
From source file:net.yatomiya.e4.util.HttpUtils.java
License:Open Source License
public static String getHostUrl(String url) { try {/* ww w . j av a 2 s. c o m*/ HttpUrl hurl = HttpUrl.parse(url); return hurl.scheme() + "://" + hurl.host(); } catch (Throwable e) { return null; } }
From source file:net.yatomiya.e4.util.StandardHttpClient.java
License:Open Source License
public Call download(String url, Date lastModifiedSince, boolean isSynchronous, Consumer<Response> responseHandler) { Request request = HttpUtils.createRequestBuilder(HttpUrl.parse(url), lastModifiedSince).build(); Callback callback = new Callback() { @Override//from ww w .j a v a 2s . c o m public void onResponse(Response response) throws IOException { responseHandler.accept(response); } @Override public void onFailure(Request request, IOException e) { responseHandler.accept(null); } }; return execute(request, callback, isSynchronous); }
From source file:net.yatomiya.nicherry.services.bbs.BoardProcessor.java
License:Open Source License
@Override public void resetAnalyzedStates() { httpUrl = HttpUrl.parse(getModel().getUrl()); }
From source file:net.yatomiya.nicherry.services.bbs.model.ThreadURL.java
License:Open Source License
public ThreadURL(String urlString) { httpUrl = HttpUrl.parse(urlString); List<String> seg = httpUrl.pathSegments(); if (seg.size() != 4 && seg.size() != 5) throw new IllegalArgumentException("Thread path segments size should be 5 or 6."); if (!seg.get(0).equalsIgnoreCase("test") || !seg.get(1).equalsIgnoreCase("read.cgi")) throw new IllegalArgumentException("url does not contain \\\"test/read.cgi\\\"."); boardKey = seg.get(2);//from w ww . j a v a 2s . c o m threadKey = seg.get(3); if (seg.size() >= 5) { messageParam = new MessageParam(seg.get(4)); } else { messageParam = MessageParam.ALL; } }
From source file:net.yatomiya.nicherry.services.bbs.model.URLToken.java
License:Open Source License
public URLToken(AnalyzedMessage message, int offset, int length, String text, String urlString) { super(message, offset, length, text); url = HttpUrl.parse(urlString); if (url == null) { url = HttpUrl.parse("http://localhost/"); }/*from w w w . ja v a 2 s . c om*/ ext = StringUtils.getExtension(HttpUtils.getPathName(url)); }