Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.redheademile.matt;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.nio.channels.Channels;
- import java.nio.channels.ReadableByteChannel;
- import java.util.ArrayList;
- public class Matt
- {
- public static void main(String[] args)
- {
- new Matt();
- }
- public Matt()
- {
- File folder = new File("C:\\Users\\emili\\Documents\\kamek");
- int increment = 50, count = 0;
- for(int i = 0; i < 900; i += increment)
- {
- try
- {
- String content = savePage("https://git.wuffs.org/kamek/log/?h=resurrection&ofs="+Integer.toString(i));
- String[] result = getBeetween(content, "href='", "'>");
- for(int j = 0; j < result.length; j++)
- {
- if(result[j].contains("commit/") && result[j].contains("id="))
- {
- count++;
- String id = result[j].split("id=")[1];
- String url = "https://git.wuffs.org/kamek/snapshot/kamek-"+id+".zip";
- URL website = new URL(url);
- ReadableByteChannel rbc = Channels.newChannel(website.openStream());
- FileOutputStream fos = new FileOutputStream(new File(folder, "kamek-"+id+".zip"));
- fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
- fos.close();
- rbc.close();
- System.out.println(count + "/ 893 (supposé)");
- }
- }
- }
- catch(IOException e)
- {
- System.out.println("Erreur sur la page "+Integer.toString(i));
- }
- }
- }
- public String[] getBeetween(String str, String behind, String front)
- {
- ArrayList<String> words = new ArrayList<>();
- for(String str_ : str.split(behind))
- {
- try
- {
- if(str_.contains(front))
- {
- //System.out.println(str_);
- words.add(str_.split(front)[0]);
- }
- }
- catch(Exception e) {}
- }
- return words.toArray(new String[words.size()]);
- }
- public String savePage(final String URL) throws IOException
- {
- String line = "", all = "";
- URL myUrl = null;
- BufferedReader in = null;
- try {
- myUrl = new URL(URL);
- in = new BufferedReader(new InputStreamReader(myUrl.openStream()));
- while ((line = in.readLine()) != null) all += line;
- }
- finally
- {
- if (in != null) in.close();
- }
- return all;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement