A few days ago, my sister suddenly told me that she bought an e-book on JD. After buying it, she found that she could only read it online or using its own reader. It was very inconvenient, so I asked me to think of a solution.
I started to think about it. At the beginning, I directly used Acrobat Reader to open it and found that there were only directories, nothing else, and the pages were all present. I thought that a mask might be added to the correct content. People who can only use the "key" can filter it. To crack other people's editors, it will definitely not work in a short time. Many people on the Internet also thought of using automated scripts to automatically take screenshots of official readers, but I found that the screenshots are not page by page, which is very confused. Finally, I can only find a way by reading this line online.
This method is similar to those of netizens. It is saved as a picture, and how to make it into a pdf through the pdf tool.
I was surprised to find that the document is really good, with one picture per page, it has been done for you, but only the first and last few pictures of the current page will be updated at a time, and the others will be cleared. At this point, there is a way of thinking:
Steps 1 to 3 need to be repeated and can be implemented using automated tools and scripts.
Step 4 Just write a controller, just the simplest Java interface.
Step 5: Direct online service can be achieved.
Why do we need to cache the download first? This involves a problem of efficiency, image deduplication and filtering, because the images obtained after each adjustment may be duplicated, and the reduplication will be automatically deduplicated; it is also to avoid problems such as abnormal exit in the middle of the download while obtaining the image path and other tasks that cannot be executed normally. Then the script gets the path and saves it to your own server. The only problem may be the cross-domain problem. As a result, I found that there were still a few pictures missing, which made me realize the benefits of using cache. I can directly verify that those pictures were missing through the code without checking the jpg file, the number of files with fewer single digits, and finally completed manually.
The only flaw in the pictures obtained in this way is that they have the words "JD Reading" and the picture resolution is not very high, and the font seems to have some furry. If you have obsessive-compulsive disorder or pursue high quality, use the official reader. I personally read it clearly, it is a document, not a picture! ! !
The following is the code to save network data to the local area through URL.
public class HttpURLConnectionUtil {// Data stream to get the reader response data through get request public static InputStream getInputStreamByGet(String url) { try { HttpURLConnection conn = (HttpURLConnection) new URL(url) .openConnection(); conn.setReadTimeout(5000); conn.setConnectTimeout(5000); conn.setRequestMethod("GET"); if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { InputStream inputStream = conn.getInputStream(); return inputStream; } } catch (IOException e) { e.printStackTrace(); } return null;}// Save the data response of the server to the local file public static void saveData(InputStream is, File file) { try (BufferedInputStream bis = new BufferedInputStream(is); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(file));) { byte[] buffer = new byte[1024]; int len = -1; while ((len = bis.read(buffer)) != -1) { bos.write(buffer, 0, len); bos.flush(); } } catch (IOException e) { e.printStackTrace(); }}}Called:
Set<String> imgNumber = (Set<String>) redisTemplate.opsForHash().keys(MAP_KEY);imgNumber.stream().forEach(e->{ String url = (String) redisTemplate.opsForHash().get(MAP_KEY,e); String fileName = e+".jpg"; File file = new File("E://pdf image//", fileName); InputStream inputStream = HttpURLConnectionUtil .getInputStreamByGet(url); HttpURLConnectionUtil.saveData(inputStream, file);});Summarize
The above is the example code that the editor introduced to you about java reading remote data through url and keeping it locally. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!