├── CalculoIMC └── CalculoIMC.java ├── Classes de Ajuda ├── Contador │ ├── Contador.java │ └── README.md ├── EDownloaderInfo │ ├── EDownloaderInfo.java │ └── README.md ├── GetJSON │ ├── GetJSON.java │ └── README.md ├── Logg │ ├── Logg.java │ └── README.md └── README.md ├── LICENSE └── README.md /CalculoIMC/CalculoIMC.java: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2016 Wolfgang Almeida 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | import java.util.Scanner; 26 | 27 | class CalculoIMC { 28 | public static String classificarIMC(double imc) { 29 | if (imc < 16.0) { 30 | return "Magreza grave"; 31 | } 32 | else if (imc == 16.0 || imc < 17.0) { 33 | return "Magreza moderada"; 34 | } 35 | else if (imc == 17.0 || imc < 18.5) { 36 | return "Magreza leve"; 37 | } 38 | else if (imc == 18.5 || imc < 25.0) { 39 | return "Saudável"; 40 | } 41 | else if (imc == 25.0 || imc < 30.0) { 42 | return "Sobrepeso"; 43 | } 44 | else if (imc == 30.0 || imc < 35.0) { 45 | return "Obesidade Grau I"; 46 | } 47 | else if (imc == 35.0 || imc < 40.0) { 48 | return "Obesidade Grau II"; 49 | } 50 | else { 51 | return "Obesidade Grau III"; 52 | } 53 | } 54 | 55 | public static double calcularPeso(double peso, double altura) { 56 | return peso / (altura * altura); 57 | } 58 | 59 | public static void programaIMC(String versao) { 60 | double peso, altura, imc; 61 | Scanner pScan = new Scanner(System.in); 62 | Scanner aScan = new Scanner(System.in); 63 | 64 | System.out.println("==========================="); 65 | System.out.printf("Cálculo do IMC - Versão %s\n", versao); 66 | System.out.println("==========================="); 67 | 68 | System.out.print("Insira o seu peso em quilogramas: "); 69 | peso = Double.parseDouble(pScan.nextLine()); 70 | 71 | System.out.print("Insira o sua altura em metros: "); 72 | altura = Double.parseDouble(aScan.nextLine()); 73 | 74 | imc = calcularPeso(peso, altura); 75 | 76 | System.out.printf("\nSeu índice de massa corporal é: %.2f kg/m²\n", imc); 77 | System.out.printf("Classificação: %s.\n", classificarIMC(imc)); 78 | } 79 | 80 | public static void main(String[] args) { 81 | String versao = "1.0"; 82 | programaIMC(versao); 83 | } 84 | } -------------------------------------------------------------------------------- /Classes de Ajuda/Contador/Contador.java: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2017 Wolfgang Almeida 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | import java.time.*; 26 | 27 | // VERSÃO 1.1 28 | 29 | public class Contador extends Thread { 30 | // Propriedades privadas 31 | // ===================== 32 | private int time = 0; 33 | private int limit = -1; 34 | private boolean running = true; 35 | 36 | // Construtores da classe 37 | // ====================== 38 | public Contador(int limit) { 39 | this.limit = limit; 40 | 41 | if(this.limit <= 0) { 42 | this.limit = 0; 43 | } 44 | } 45 | 46 | public Contador() { 47 | this.limit = -1; 48 | } 49 | 50 | // Métodos públicos 51 | // ================ 52 | 53 | // Iniciando Thread 54 | // ================ 55 | @Override 56 | public void run() { 57 | while(running) { 58 | time += 1; 59 | 60 | try { 61 | Thread.sleep(1000); 62 | } 63 | catch(InterruptedException e) { 64 | e.printStackTrace(); 65 | running = false; 66 | } 67 | 68 | if(limit != -1 && time == limit) { 69 | running = false; 70 | } 71 | } 72 | } 73 | 74 | // Resgatando o tempo em segundos 75 | // ============================== 76 | public int getTime() { 77 | return time; 78 | } 79 | 80 | // Resgatando o tempo formatado 81 | // ============================ 82 | public String getTimeFormatted() { 83 | LocalTime t = LocalTime.ofSecondOfDay(time); 84 | return t.toString(); 85 | } 86 | 87 | // Parando Thread 88 | // ============== 89 | public void stopCounter() { 90 | running = false; 91 | } 92 | 93 | // Verificando se o contador ainda está ativo 94 | // ========================================== 95 | public boolean isRunning() { 96 | return running; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Classes de Ajuda/Contador/README.md: -------------------------------------------------------------------------------- 1 | ## Contador.java 2 | #### Descrição: 3 | 4 | ##### Esta pequena classe possui a função de criar um pequeno relógio que poderá ser utilizado como um contador de tempo de execução do programa ou de outras funções essenciais do programa, como o tempo de execução de um método ou loop ou o tempo entre um método e outro. 5 | 6 | ##### É possível iniciar um objeto Contador de duas maneiras: Sem tempo limite ou com tempo limite, em segundos. 7 | ##### Caso utilize um tempo limite estabelecido, o contador irá encerrar automaticamente quando chegar a marca estabelecida e não haverá necessidade de encerrá-lo manualmente. 8 | 9 | ##### Veja os exemplos abaixo: 10 | ```Java 11 | // Contador sem tempo limite 12 | Contador d = new Contador(); 13 | d.start(); 14 | 15 | // Contador com tempo limite (em segundos) 16 | Contador c = new Contador(45); 17 | c.start(); 18 | ``` 19 | 20 | ##### O contador poderá retornar três tipos de dados utilizando três métodos disponíveis: 21 | ```Java 22 | // Retorna o tempo formatado em String 23 | public String getTimeFormatted(); 24 | 25 | // Retorna o tempo (segundos) em int 26 | public int getTime(); 27 | 28 | // Verifica se o contador ainda está rodando 29 | public boolean isRunning(); 30 | ``` 31 | 32 | ##### O contador irá funcionar em uma Thread separada e só irá parar (caso não tenha inserido um tempo limite) ao invocar o seguinte método: 33 | ```Java 34 | // Para o contador por completo 35 | public void stopCounter(); 36 | ``` 37 | 38 | #### Requerimentos: 39 | - Java 8 40 | 41 | #### Exemplos de uso: 42 | 43 | - Sem tempo limite: 44 | ```Java 45 | Contador d = new Contador(); 46 | d.start(); 47 | 48 | // -------------------------------- 49 | // Vários métodos e loops depois... 50 | // -------------------------------- 51 | 52 | String tempoGasto = String.format("Tempo gasto: %s (%d segundos)!", 53 | d.getTimeFormatted(), d.getTime()); 54 | System.out.println(tempoGasto); // Tempo gasto: 00:00:32 (32 segundos)! 55 | 56 | d.stopCounter(); 57 | ``` 58 | 59 | - Com tempo limite 60 | ```Java 61 | Contador c = new Contador(45); 62 | c.start(); 63 | 64 | while(c.isRunning()) { 65 | String msg = String.format("\rTempo: %s", c.getTimeFormatted()); 66 | 67 | System.out.print(msg); 68 | System.out.flush(); 69 | } 70 | System.out.println(""); 71 | ``` -------------------------------------------------------------------------------- /Classes de Ajuda/EDownloaderInfo/EDownloaderInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2017 Wolfgang Almeida 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | package io.github.wolfterro; 26 | 27 | import java.io.*; 28 | import java.util.*; 29 | import java.net.*; 30 | 31 | import org.jsoup.*; 32 | import org.jsoup.nodes.*; 33 | import org.jsoup.select.*; 34 | 35 | // VERSÃO 1.1 36 | 37 | public class EDownloaderInfo { 38 | // Propriedades privadas 39 | // ===================== 40 | 41 | // Propriedades recebidas 42 | // ---------------------- 43 | private String albumURL = ""; 44 | 45 | // Propriedades enviadas ou estocadas 46 | // ---------------------------------- 47 | private Document doc = null; 48 | 49 | private Elements links = null; 50 | 51 | private List imagePages = new ArrayList(); 52 | private List albumPages = new ArrayList(); 53 | 54 | // As propriedades abaixo poderão retornar 55 | // --------------------------------------- 56 | private ArrayList imageLinks = new ArrayList(); 57 | 58 | private String albumName = ""; 59 | private String albumLanguage = ""; 60 | private String uploadDate = ""; 61 | private String uploader = ""; 62 | private String fileSize = ""; 63 | private String error = ""; 64 | 65 | private int pages = 0; 66 | 67 | private boolean isTranslated = false; 68 | private boolean isOk = false; 69 | 70 | // Construtor da Classe 71 | // ==================== 72 | public EDownloaderInfo(String albumURL) { 73 | this.albumURL = albumURL; 74 | } 75 | 76 | // ================ 77 | // Métodos privados 78 | // ================ 79 | 80 | // Recuperando informações sobre o álbum 81 | // ------------------------------------- 82 | private boolean pGetInfo() { 83 | if(!checkURLDomain()) { 84 | error = "INVALID_URL_ERROR"; 85 | return false; 86 | } 87 | 88 | try { 89 | doc = Jsoup.connect(albumURL).cookie("nw", "1").get(); 90 | albumName = String.format("%s", doc.title()).replace(" - E-Hentai Galleries", ""); 91 | 92 | pGetAlbumLanguage(); 93 | pGetUploader(); 94 | pGetUploadDate(); 95 | pGetFileSize(); 96 | pGetAlbumPages(); 97 | pGetImagePages(); 98 | pGetImageLinks(); 99 | 100 | pages = imageLinks.size(); 101 | 102 | return true; 103 | } 104 | catch(IOException e) { 105 | e.printStackTrace(); 106 | error = "IO_EXCEPTION_AT_pGetInfo()"; 107 | return false; 108 | } 109 | } 110 | 111 | // Verificando se a URL pertence ao site 112 | // ------------------------------------- 113 | private boolean checkURLDomain() { 114 | try { 115 | URL u = new URL(albumURL); 116 | if(u.getAuthority().equals("e-hentai.org")) { 117 | // Caso o usuário insira além da primeira página 118 | // --------------------------------------------- 119 | albumURL = albumURL.replaceAll("\\?p=.*", ""); 120 | return true; 121 | } 122 | else { 123 | return false; 124 | } 125 | } catch (MalformedURLException e) { 126 | e.printStackTrace(); 127 | return false; 128 | } catch (Exception e) { 129 | e.printStackTrace(); 130 | return false; 131 | } 132 | } 133 | 134 | // Resgatando idioma do álbum 135 | // -------------------------- 136 | private void pGetAlbumLanguage() { 137 | links = doc.select("div[id=gdd]"); 138 | 139 | for(Element e : links) { 140 | Elements table = e.getElementsByTag("table"); 141 | 142 | for(Element t : table) { 143 | Elements row = t.getElementsByTag("tr"); 144 | 145 | for(Element l : row) { 146 | Elements lang = l.getElementsByClass("gdt2"); 147 | Elements langDescr = l.getElementsByClass("gdt1"); 148 | 149 | int i = 0; 150 | for(Element ll : langDescr) { 151 | if(ll.text().toString().contains("Language")) { 152 | if(lang.get(i).text().toString().contains("TR")) { 153 | isTranslated = true; 154 | } 155 | 156 | albumLanguage = lang.get(i) 157 | .text() 158 | .toString() 159 | .replace("  ", "") 160 | .replace("TR", ""); 161 | return; 162 | } 163 | 164 | i += 1; 165 | } 166 | } 167 | } 168 | } 169 | } 170 | 171 | // Resgatando nome do uploader 172 | // --------------------------- 173 | private void pGetUploader() { 174 | links = doc.select("div[id=gdn]"); 175 | 176 | for(Element e : links) { 177 | Elements uplName = e.getElementsByTag("a"); 178 | uploader = uplName.text().toString(); 179 | } 180 | } 181 | 182 | // Resgatando data do upload 183 | // ------------------------- 184 | private void pGetUploadDate() { 185 | links = doc.select("div[id=gdd]"); 186 | 187 | for(Element e : links) { 188 | Elements table = e.getElementsByTag("table"); 189 | 190 | for(Element t : table) { 191 | Elements row = t.getElementsByTag("tr"); 192 | 193 | for(Element d : row) { 194 | Elements date = d.getElementsByClass("gdt2"); 195 | 196 | for(Element dd : date) { 197 | uploadDate = dd.text().toString() 198 | .replace("-", "/") 199 | .replace(" ", " - "); 200 | return; 201 | } 202 | } 203 | } 204 | } 205 | } 206 | 207 | // Resgatando tamanho do álbum 208 | // --------------------------- 209 | private void pGetFileSize() { 210 | links = doc.select("div[id=gdd]"); 211 | String bytes[] = {"B", "KB", "MB", "GB", "TB"}; 212 | 213 | for(Element e : links) { 214 | Elements table = e.getElementsByTag("table"); 215 | 216 | for(Element t : table) { 217 | Elements row = t.getElementsByTag("tr"); 218 | 219 | for(Element f : row) { 220 | Elements fs = f.getElementsByClass("gdt2"); 221 | 222 | for(String b : bytes) { 223 | if(fs.text().toString().endsWith(b)) { 224 | fileSize = fs.text().toString(); 225 | } 226 | } 227 | } 228 | } 229 | } 230 | } 231 | 232 | // Resgatando páginas do álbum, da forma como é mostrado no site 233 | // ------------------------------------------------------------- 234 | private void pGetAlbumPages() { 235 | links = doc.select("a[href]"); 236 | 237 | for(Element e : links) { 238 | if(e.absUrl("href").contains("?p=")) { 239 | if(!albumPages.contains(e.absUrl("href"))) { 240 | albumPages.add(e.absUrl("href")); 241 | } 242 | } 243 | } 244 | } 245 | 246 | // Resgatando link das imagens, como são mostradas no site 247 | // ------------------------------------------------------- 248 | private void pGetImagePages() { 249 | for(Element e : links) { 250 | if(e.absUrl("href").startsWith("https://e-hentai.org/s/")) { 251 | imagePages.add(e.absUrl("href")); 252 | } 253 | } 254 | 255 | if(albumPages.size() >= 1) { 256 | for(int i = 0; i < albumPages.size(); i++) { 257 | try { 258 | doc = Jsoup.connect(albumPages.get(i)).cookie("nw", "1").get(); 259 | links = doc.select("a[href]"); 260 | 261 | for(Element e : links) { 262 | if(e.absUrl("href").startsWith("https://e-hentai.org/s/")) { 263 | imagePages.add(e.absUrl("href")); 264 | } 265 | } 266 | } 267 | catch(IOException e) { 268 | e.printStackTrace(); 269 | } 270 | } 271 | } 272 | } 273 | 274 | // Resgatando link absoluto das imagens através das páginas 275 | // -------------------------------------------------------- 276 | private void pGetImageLinks() { 277 | for(int i = 0; i < imagePages.size(); i++) { 278 | try { 279 | doc = Jsoup.connect(imagePages.get(i)).cookie("nw", "1").get(); 280 | links = doc.select("img[id=img]"); 281 | 282 | for(Element img : links) { 283 | imageLinks.add(img.absUrl("src")); 284 | } 285 | } 286 | catch(IOException e) { 287 | e.printStackTrace(); 288 | } 289 | } 290 | } 291 | 292 | // ================ 293 | // Métodos públicos 294 | // ================ 295 | 296 | // Iniciando processo de resgate de valores do álbum 297 | // ------------------------------------------------- 298 | public void getInfo() { 299 | isOk = pGetInfo(); 300 | } 301 | 302 | // Verificando se o processo foi concluído com sucesso 303 | // --------------------------------------------------- 304 | public boolean isSuccessful() { 305 | return isOk; 306 | } 307 | 308 | // Resgatando link absoluto das imagens 309 | // ------------------------------------ 310 | public ArrayList getImages() { 311 | return imageLinks; 312 | } 313 | 314 | // Resgatando número de páginas (imagens) do álbum 315 | // ----------------------------------------------- 316 | public int getAlbumSize() { 317 | return pages; 318 | } 319 | 320 | // Resgatando nome do álbum 321 | // ------------------------ 322 | public String getAlbumName() { 323 | return albumName; 324 | } 325 | 326 | // Resgatando idioma do álbum 327 | // -------------------------- 328 | public String getAlbumLanguage() { 329 | return albumLanguage; 330 | } 331 | 332 | // Verificando se o álbum é uma tradução 333 | // ------------------------------------- 334 | public boolean isTranslated() { 335 | return isTranslated; 336 | } 337 | 338 | // Resgatando nome do uploader 339 | // --------------------------- 340 | public String getUploader() { 341 | return uploader; 342 | } 343 | 344 | // Resgatando data do upload 345 | // ------------------------- 346 | public String getUploadDate() { 347 | return uploadDate; 348 | } 349 | 350 | // Resgatando tamanho do álbum 351 | // --------------------------- 352 | public String getFileSize() { 353 | return fileSize; 354 | } 355 | 356 | // Resgatando mensagem de erro 357 | // --------------------------- 358 | public String getError() { 359 | return error; 360 | } 361 | } 362 | -------------------------------------------------------------------------------- /Classes de Ajuda/EDownloaderInfo/README.md: -------------------------------------------------------------------------------- 1 | ## EDownloaderInfo.java 2 | #### Descrição: 3 | 4 | ##### Esta pequena classe possui a função de resgatar as informações disponíveis nos álbuns do website e-hentai. 5 | ##### Esta classe permite, por exemplo, obter o endereço de todas as imagens disponíveis no álbum, o nome do álbum, o idioma do álbum, se foi traduzido ou não, o uploader, a data do upload, o tamanho do álbum e a quantidade de imagens disponíveis no álbum. Com isso, será possível baixar as imagens utilizando os endereços resgatados. 6 | ##### Para isso, a classe utiliza a biblioteca [org.jsoup](https://github.com/jhy/jsoup) para obter estas informações diretamente do álbum. 7 | 8 | ##### É possível inicializar o objeto EDownloaderInfo utilizando apenas a URL do álbum em String da seguinte maneira: 9 | ```Java 10 | EDownloaderInfo e = new EDownloaderInfo(String albumURL); 11 | ``` 12 | 13 | ##### Após inicializar o objeto com a URL do álbum desejado, basta chamar o método getInfo() para iniciar o processo de resgate de valores: 14 | ```Java 15 | EDownloaderInfo e = new EDownloaderInfo(url); 16 | e.getInfo(); 17 | ``` 18 | 19 | ##### Dependendo do álbum escolhido, este processo pode levar um tempo, deixando a Thread principal ocupada. É recomendável que você utilize esta classe em uma Thread separada, especialmente se estiver utilizando alguma interface gráfica ou integrando diretamente em um aplicativo Android. 20 | 21 | ##### Se o processo for bem sucedido, será possível obter os valores resgatados utilizando alguns métodos. Abaixo está a descrição de todos eles: 22 | ```Java 23 | // Verificando se o processo foi concluído com sucesso 24 | public boolean isSuccessful(); 25 | 26 | // Resgata link absoluto das imagens 27 | public ArrayList getImages(); 28 | 29 | // Resgata número de páginas (imagens) do álbum 30 | public int getAlbumSize(); 31 | 32 | // Resgata nome do álbum 33 | public String getAlbumName(); 34 | 35 | // Resgata o idioma do álbum 36 | public String getAlbumLanguage(); 37 | 38 | // Verificando se o álbum é uma tradução 39 | public boolean isTranslated(); 40 | 41 | // Resgatando nome do uploader 42 | public String getUploader(); 43 | 44 | // Resgatando data do upload (yyyy/MM/dd - HH:mm) 45 | public String getUploadDate(); 46 | 47 | // Resgatando tamanho do álbum (arquivos) 48 | public String getFileSize(); 49 | 50 | // Resgata mensagem de erro (se houver, caso contrário retorna String vazia) 51 | public String getError(); 52 | ``` 53 | 54 | #### Requerimentos: 55 | - Java 8 56 | - org.jsoup 57 | 58 | #### Exemplo de uso: 59 | ```Java 60 | // albumURL é uma String, contendo o endereço do álbum desejado 61 | EDownloaderInfo e = new EDownloaderInfo(albumURL); 62 | e.getInfo(); 63 | 64 | if(e.isSuccessful()) { 65 | System.out.println("Nome do álbum: " + e.getAlbumName()); 66 | System.out.println("Idioma: " + e.getAlbumLanguage()); 67 | System.out.println("Tradução: " + e.isTranslated()); 68 | System.out.println("Uploader: " + e.getUploader()); 69 | System.out.println("Data: " + e.getUploadDate()); 70 | System.out.println("Tamanho: " + e.getFileSize()); 71 | System.out.println("Número de páginas: " + e.getAlbumSize()); 72 | 73 | System.out.println("\nLink absoluto das imagens:"); 74 | System.out.println("--------------------------"); 75 | 76 | For(String img : e.getImages()) { 77 | System.out.println(img); 78 | } 79 | } 80 | else { 81 | System.out.println("Erro! Não foi possível resgatar informações do álbum!"); 82 | System.out.println("Erro: " + e.getError()); 83 | } 84 | ``` 85 | 86 | ##### Ao utilizar uma URL correta para o álbum, o processo poderá ser iniciado sem grandes problemas. Caso utilize uma URL que não pertença ao e-hentai.org, isSuccessful() irá retornar falso e uma mensagem de erro será gerada para getError(). 87 | -------------------------------------------------------------------------------- /Classes de Ajuda/GetJSON/GetJSON.java: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2017 Wolfgang Almeida 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | package io.github.wolfterro; 26 | 27 | import java.io.IOException; 28 | import java.io.InputStream; 29 | import java.net.*; 30 | import java.util.Scanner; 31 | 32 | import org.json.*; 33 | 34 | // VERSÃO 1.0 35 | 36 | // Classe responsável por resgatar o arquivo .json de uma API pública 37 | // ================================================================== 38 | public class GetJSON { 39 | // Propriedades privadas 40 | // ===================== 41 | private JSONObject obj = null; 42 | private String apiURL = ""; 43 | 44 | // Construtor da classe 45 | // ==================== 46 | public GetJSON(String apiURL) { 47 | this.apiURL = apiURL; 48 | } 49 | 50 | // Métodos privados da classe 51 | // ========================== 52 | private void getJSON() { 53 | try { 54 | URL u = new URL(apiURL); 55 | HttpURLConnection conn = (HttpURLConnection) u.openConnection(); 56 | conn.connect(); 57 | 58 | InputStream stream = (InputStream) conn.getContent(); 59 | 60 | Scanner s = new Scanner(stream); 61 | s.useDelimiter("\\A"); 62 | String res = s.hasNext() ? s.next() : ""; 63 | s.close(); 64 | 65 | obj = new JSONObject(res); 66 | } 67 | catch(MalformedURLException e) { 68 | e.printStackTrace(); 69 | } 70 | catch(IOException e) { 71 | e.printStackTrace(); 72 | } 73 | } 74 | 75 | // Métodos públicos da classe 76 | // ========================== 77 | public JSONObject get() { 78 | getJSON(); 79 | return obj; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Classes de Ajuda/GetJSON/README.md: -------------------------------------------------------------------------------- 1 | ## GetJSON.java 2 | #### Descrição: 3 | 4 | ##### Esta pequena classe possui a função de resgatar os arquivos .json de uma API pública qualquer, fornecida pelo usuário através de uma URL em formato String. 5 | 6 | #### Requerimentos: 7 | - org.json 8 | 9 | #### Exemplo de uso: 10 | 11 | ```Java 12 | GetJSON g = new GetJSON("https://example.com/json"); 13 | JSONObject j = g.get(); 14 | ``` -------------------------------------------------------------------------------- /Classes de Ajuda/Logg/Logg.java: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2017 Wolfgang Almeida 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | import java.io.*; 26 | import java.text.*; 27 | import java.util.*; 28 | 29 | // VERSÃO 1.0 30 | 31 | public class Logg { 32 | // Propriedades privadas 33 | // ===================== 34 | private String filename = "MyLogg.txt"; 35 | private String dateFormat = "HH:mm:ss | dd/MM/yyyy"; 36 | 37 | private PrintWriter pw = null; 38 | 39 | // Construtores da classe 40 | // ====================== 41 | public Logg() { } 42 | 43 | public Logg(String filename) { 44 | this.filename = filename; 45 | } 46 | 47 | // ================ 48 | // Métodos privados 49 | // ================ 50 | 51 | // Iniciando arquivo de log 52 | // ======================== 53 | private void initLog() { 54 | try { 55 | pw = new PrintWriter(new FileOutputStream(new File(filename), true)); 56 | } 57 | catch(IOException e) { 58 | e.printStackTrace(); 59 | pw = null; 60 | } 61 | } 62 | 63 | // ================ 64 | // Métodos públicos 65 | // ================ 66 | 67 | // Escrevendo no arquivo de log sem data 68 | // ===================================== 69 | public void writeLogg(String message) { 70 | initLog(); 71 | 72 | if(pw != null) { 73 | pw.println(message); 74 | pw.close(); 75 | } 76 | else { 77 | String err = String.format( 78 | "ERROR! Logg: PrintWriter object is Null at message: %s", 79 | message); 80 | System.err.println(err); 81 | } 82 | } 83 | 84 | public void writeLogg() { 85 | this.writeLogg(""); 86 | } 87 | 88 | // Escrevendo no arquivo de log com data 89 | // ===================================== 90 | public void writeDatedLogg(String message) { 91 | initLog(); 92 | 93 | if(pw != null) { 94 | String date = new SimpleDateFormat( 95 | dateFormat).format(new Date()); 96 | 97 | pw.println(String.format("[%s] %s", date, message)); 98 | pw.close(); 99 | } 100 | else { 101 | String err = String.format( 102 | "ERROR! Logg: PrintWriter object is Null at message: %s", 103 | message); 104 | System.err.println(err); 105 | } 106 | } 107 | 108 | public void writeDatedLogg() { 109 | this.writeDatedLogg(""); 110 | } 111 | 112 | // Configurando o formato de data 113 | // ============================== 114 | public void setDateFormat(String dateFormat) { 115 | // Testando formato de data inserido pelo usuário 116 | // ---------------------------------------------- 117 | try { 118 | SimpleDateFormat s = new SimpleDateFormat(dateFormat); 119 | this.dateFormat = dateFormat; 120 | } 121 | catch(Exception e) { 122 | // Ignorar valor no caso de falha no teste 123 | // --------------------------------------- 124 | return; 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /Classes de Ajuda/Logg/README.md: -------------------------------------------------------------------------------- 1 | ## Logg.java 2 | #### Descrição: 3 | 4 | ##### Esta pequena classe possui a função de criar um arquivo de registro (log) e registrar diversas ocorrências durante a execução do programa ao chamar os métodos de escrita disponíveis. 5 | 6 | ##### É possível iniciar um objeto Logg de duas maneiras: Com nome de arquivo customizado ou com nome de arquivo padrão (MyLogg.txt). 7 | 8 | ##### Ao iniciar o objeto com nome de arquivo, é possível inserir como forma de caminho onde o arquivo de registro estará localizado. Mas certifique-se de ser um local existente e que o programa tenha permissão de escrita naquele local, caso contrário as mensagens não poderão ser escritas e você receberá uma mensagem de erro! 9 | 10 | ##### Caso inicie o objeto utilizando o nome padrão, será criado um arquivo (MyLogg.txt) na mesma pasta que o programa está sendo executado. 11 | 12 | ##### Veja os exemplos abaixo: 13 | ```Java 14 | // Criando um registro com nome padrão 15 | Logg l = new Logg(); 16 | 17 | // Criando um registro com nome customizado 18 | Logg o = new Logg("CustomLogg.txt"); 19 | 20 | // Criando um registro com nome e caminho customizado 21 | Logg g = new Logg("/home/user/CustomLogg.txt"); 22 | ``` 23 | 24 | ##### A classe possui duas maneiras de você inserir uma mensagem no arquivo de registro: Sem data e hora ou com data e hora inseridos no início da mensagem. 25 | ```Java 26 | // Escrevendo no arquivo de log sem data e hora 27 | public void writeLogg([String message]); 28 | 29 | // Escrevendo no arquivo de log com data e hora 30 | public void writeDatedLogg([String message]); 31 | ``` 32 | 33 | ##### É possível também alterar a formatação da data e hora que serão inseridas ao invocar o método writeDatedLogg: 34 | ```Java 35 | // Configurando o formato de data (padrão: HH:mm:ss | dd/MM/yyyy) 36 | public void setDateFormat(String dateFormat); 37 | ``` 38 | 39 | ##### Os padrões de data e hora permitidos são os mesmos da classe [SimpleDateFormat](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) e estão disponíveis na documentação oficial da classe. 40 | 41 | #### Requerimentos: 42 | - Java 8 43 | 44 | #### Exemplos de uso: 45 | ```Java 46 | Logg l = new Logg("MeuLogg.txt"); 47 | 48 | l.writeLogg("Esta é uma mensagem sem data e hora!"); 49 | l.writeDatedLogg("Esta é uma mensagem com data e hora!"); 50 | 51 | l.setDateFormat("yyyy/MM/dd - HH:mm:ss"); 52 | l.writeDatedLogg("Esta é uma mensagem com data e hora formatadas!") 53 | ``` 54 | 55 | ##### O arquivo de registro MeuLogg.txt, portanto, deverá estar da seguinte maneira: 56 | ```Text 57 | Esta é uma mensagem sem data e hora! 58 | [15:03:25 | 16/08/2017] Está é uma mensagem com data e hora! 59 | [2017/08/16 - 15:03:25] Está é uma mensagem com data e hora formatadas! 60 | ``` 61 | -------------------------------------------------------------------------------- /Classes de Ajuda/README.md: -------------------------------------------------------------------------------- 1 | # Classes de Ajuda 2 | ## Pequenas classes em Java que poderão ajudar no dia-a-dia! 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Wolfgang Almeida 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Projetos em Java 2 | ## Pequenos projetos e testes simples em linguagem Java 3 | 4 | #### Os programas apresentados neste repositório são apenas projetos simples e testes escritos na linguagem Java. 5 | #### Alguns destes programas são utilitários e scripts que podem ser utilizados no dia-a-dia para realização de algumas funções. 6 | #### Os programas aqui contidos foram desenvolvidos pensando nas plataformas Linux e UNIX em geral. 7 | 8 | ## Cálculo do IMC 9 | 10 | ### Descrição: 11 | 12 | #### Este é um simples programa que possui a função de calcular o índice de massa corporal do usuário. 13 | #### O programa utiliza o terminal ou prompt de comando e pede ao usuário que insira o seu peso em quilogramas e sua altura em metros. 14 | #### Ao final do processo, o programa mostra o valor do IMC em quilogramas por metro quadrado. 15 | #### Programa similar a este e escrito em C++ pode ser encontrado neste repositório: [Projetos em C++](https://github.com/Wolfterro/Projetos-em-Cpp) 16 | 17 | ### Download: 18 | 19 | #### Utilize o git para clonar o repositório e utilize o compilador javac para criar o binário: 20 | 21 | git clone https://github.com/Wolfterro/Projetos-em-Java.git 22 | cd Projetos-em-Java/CalculoIMC 23 | javac CalculoIMC.java 24 | java CalculoIMC 25 | 26 | ## Classes de Ajuda 27 | 28 | ### Descrição: 29 | 30 | #### São pequenas classes em Java que possuem a função de ajudar o desenvolvedor a construir aplicações de forma mais rápida, sem que haja necessidade de criar diversas implementações o tempo todo. 31 | #### Para usá-las, basta alterar o package informado no arquivo para o package de seu projeto e insira o arquivo junto aos arquivos de código-fonte de seu projeto. 32 | #### Para visualizar quais classes estão disponíveis, verifique o arquivo README.md disponível dentro da pasta. 33 | 34 | ### Download: 35 | 36 | #### Utilize o git para clonar o repositório: 37 | 38 | git clone https://github.com/Wolfterro/Projetos-em-Java.git 39 | cd "Projetos-em-Java/Classes de Ajuda" 40 | --------------------------------------------------------------------------------