Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package programaAcessaSite;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.IOException;
- import java.net.URISyntaxException;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.List;
- /**
- *
- * @author Usuário
- */
- public class ManipuladorLink {
- private String pastaOrigem = "file://184.82.88.45/dofus/lang/swf/";
- private String pastaDestino = "C:/Documents and Settings/Usuário/Desktop/legalize lang/swf";
- public static void main(String[] args) {
- try {
- ManipuladorLink ml = new ManipuladorLink();
- ml.baixaArquivos();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void baixaArquivos() throws FileNotFoundException, IOException, URISyntaxException {
- List<URL> urls = getURLs();
- int totalArquivos = urls.size();
- int arquivoAtual = 0;
- for (URL url : urls) {
- File arquivoOriginal = new File(url.toURI());
- FileInputStream in = new FileInputStream(arquivoOriginal);
- BufferedInputStream bin = new BufferedInputStream(in);
- String destino = pastaDestino+getNomeArquivo(url);
- destino = destino.replaceAll("\"", "");
- FileOutputStream out = new FileOutputStream(destino);
- BufferedOutputStream bout = new BufferedOutputStream(out);
- int data = 0;
- while((data = bin.read()) != -1){
- bout.write(data);
- System.out.println("Arquivos salvos: "+(++arquivoAtual)+" de "+totalArquivos);
- }
- }
- }
- private String getNomeArquivo(URL url){
- String path = url.getPath();
- String nomeArquivo = path.substring(path.lastIndexOf("/")+1, path.length());
- return nomeArquivo;
- }
- public void imprimeURLs() throws FileNotFoundException, IOException, URISyntaxException {
- List<URL> urls = getURLs();
- for (URL url : urls) {
- String path = url.getPath();
- System.out.println(path.substring(path.lastIndexOf("/")+1, path.length()));
- }
- System.out.println("Total arquivos: " + urls.size());
- }
- public List<URL> getURLs() throws FileNotFoundException, IOException, URISyntaxException {
- List<URL> urls = new ArrayList<URL>();
- File codigoFonte = new File(getClass().getResource("CodigoFonteManipulaLink.html").toURI());
- BufferedReader br = new BufferedReader(new FileReader(codigoFonte));
- String linha = null;
- while ((linha = br.readLine()) != null) {
- String nomeArquivo = getNomeArquivoSWF(linha);
- if (nomeArquivo != null) {
- urls.add(new URL((pastaOrigem + nomeArquivo).replaceAll("\"", "")));
- }
- }
- return urls;
- }
- public String getNomeArquivoSWF(String link) {
- String nomeArquivo = null;
- if (link.contains(".swf")) {
- int indexInicio = link.indexOf("href=");
- int indexFim = link.indexOf("</a>");
- nomeArquivo = link.substring(indexInicio, indexFim);
- nomeArquivo = nomeArquivo.replaceAll("href=", "");
- nomeArquivo = nomeArquivo.replaceAll("'", "");
- nomeArquivo = nomeArquivo.split(">")[0];
- }
- return nomeArquivo;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment