first commit
No files matched your search
@@ -0,0 +1,25 @@
|
|||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
replay_pid*
|
||||||
|
.fake
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar",
|
||||||
|
"gson-2.10.1.jar"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
## Alura-Stickers
|
||||||
|
|
||||||
|
Projeto desenvolvido na imersão Java da Alura, realizada entre os dias 27/03/2023 e 31/03/2023. Trata-se de um programa em Java para baixar imagens de algumas APIs e gerar figurinhas para redes sociais.
|
||||||
|
|
||||||
|
Clique na imagem abaixo para assistir o vídeo.
|
||||||
|
|
||||||
|
[](https://www.youtube.com/watch?v=ujaCt-Mt6Qo)</li>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<h3>Aula 01 | 27/03/2023 | Consumindo uma API de filmes com o Java.</h3>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<b>Objetivo:</b> Obter o título, poster e rating dos 250 melhores filmes do IMDB. Uma vez que a API do IMDB estava apresentando instabilidades, não foi possível utilizar a API oficial. Em vez disso, foram utilizados links alternativos oferecidos pelos instrutores da imersão.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>Desafios:</b>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<b>Consumir o endpoint de filmes mais populares da API do IMDB. Procure também, na documentação da API do IMDB, o endpoint que retorna as melhores séries e o que retorna as séries mais populares:</b> Esta etapa foi realizada, mas como o link foi exportado para um arquivo separado, então optou-se por colocar todos os links solicitados e fazer o teste em uma única execução, exibindo o resultado dos 4 links.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>Usar sua criatividade para deixar a saída dos dados mais bonitinha: usar emojis com código UTF-8, mostrar a nota do filme como estrelinhas, decorar o terminal com cores, negrito e itálico usando códigos ANSI, e mais:</b> Desafio realizado, mas notou-se que a estrela é exibida de forma diferente no cmd do windows. Além das cores e do emoji de estrela para exibir o rating do filme, também foi inserido um símbolo de like se o rating do filme for maior ou igual a 5 e um emoji de deslike se o rating for inferior a 5.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>Colocar a chave da API do IMDB em algum lugar fora do código como um arquivo de configuração (p. ex, um arquivo .properties) ou uma variável de ambiente:</b> Não foi possível obter a chave devido à instabilidade da API do IMDB. Deste modo, foram colocados os links em um arquivo de configuração somente para concluir o desafio. Os links ficaram no arquivo Link.txt.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<h3>Aula 02 | 28/03/2023 | Gerando figurinhas para WhatsApp.</h3>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<b>Objetivo:</b> Gerar figurinhas para WhatsApp a partir das imagens fornecidas pela API da IMDB. Mais uma vez, devido à instabilidade do IMDB, foram utilizados os links alternativos oferecidos pelos instrutores. Foi percebido que as figurinhas de alguns filmes não eram geradas devido a presença de dois pontos (:) no nome do arquivo. Para resolver este problema os dois pontos (:) foram substituídos por traço (-).
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>Desafios:</b>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<b>Criar diretório de saída das imagens, se ainda não existir: </b> Desafio realizado.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>Centralizar o texto na figurinha:</b> Desafio realizado.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>Colocar outra fonte como a Comic Sans ou a Impact, a fonte usada em memes: </b> Desafio Realizado. Foi colocado a Comic Sans.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>Colocar contorno (outline) no texto da imagem: </b> Desafio Realizado.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>Colocar uma imagem de você que está fazendo esse curso sorrindo, fazendo joinha e fazer com que o texto da figurinha seja personalizado de acordo com as classificações do IMDB: </b> Desafio Realizado. Entretanto, nos links fornecidos só há filmes com rating superior a 5 e por isso apenas a mensagem <i><b>Recomendo</b></i> e sua respectiva imagem foram exibidos.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<h3>Aula 03 | 29/03/2023 | Ligando as pontas: Refatoração e orientação a objetos.</h3>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<b>Objetivo:</b> Obter imagens da API da Nasa e refatorar o código utilizando orientação à objetos. Obs: Para manter a compatibilidade e utilizar tanto a API do IMDB como a API da Nasa, foram removidos os emojis do terminal e os links foram colocados no código. Foi necessário refazer a classe JSonParser, pois não estava obtendo os dados corretamente, sendo que para isso foi utilizado Google GSON e a classe JsonParser foi modificada para MyJSonParser a fim de evitar conflitos.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>Desafios:</b>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<b>Transformar a classe que representa os conteúdos em um Record, disponível a partir do Java 16: </b> Desafio realizado.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>Criar as suas próprias exceções e usá-las na classe que implementa o cliente HTTP:</b> Desafio realizado.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>Usar recursos do Java 8 e posterior, como Streams e Lambdas, para mapear uma lista em uma outra: </b> Desafio Realizado.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>Criar uma Enum que une, como configurações, a URL da API e o extrator utilizado: </b> Desafio Realizado.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<h3>Aula 04 | 30/03/2023 | Criando nossa própria API com Spring.</h3>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<b>Objetivo:</b> Obter figurinhas a partir de uma API própria.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<h3>Aula 05 | 31/03/2023 | Publicando nossa API no Cloud.</h3>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<b>Objetivo:</b> Utilizar API própria publicada no Fly.io.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Created-By: 11.0.16.1 (Azul Systems, Inc.)
|
||||||
|
Build-Jdk-Spec: 11
|
||||||
|
Bnd-LastModified: 1673019830620
|
||||||
|
Bundle-ContactAddress: https://github.com/google/gson
|
||||||
|
Bundle-Description: Gson JSON library
|
||||||
|
Bundle-Developers: google;organization=Google;organizationUrl="https://w
|
||||||
|
ww.google.com"
|
||||||
|
Bundle-DocURL: https://github.com/google/gson/gson
|
||||||
|
Bundle-License: "Apache-2.0";link="https://www.apache.org/licenses/LICEN
|
||||||
|
SE-2.0.txt"
|
||||||
|
Bundle-ManifestVersion: 2
|
||||||
|
Bundle-Name: Gson
|
||||||
|
Bundle-RequiredExecutionEnvironment: JavaSE-1.7, JavaSE-1.8
|
||||||
|
Bundle-SCM: url="https://github.com/google/gson/gson/",connection="scm:g
|
||||||
|
it:https://github.com/google/gson.git/gson",developer-connection="scm:g
|
||||||
|
it:git@github.com:google/gson.git/gson",tag="gson-parent-2.10.1"
|
||||||
|
Bundle-SymbolicName: com.google.gson
|
||||||
|
Bundle-Vendor: Google Gson Project
|
||||||
|
Bundle-Version: 2.10.1
|
||||||
|
Export-Package: com.google.gson;uses:="com.google.gson.reflect,com.googl
|
||||||
|
e.gson.stream";version="2.10.1",com.google.gson.annotations;version="2.
|
||||||
|
10.1",com.google.gson.reflect;version="2.10.1",com.google.gson.stream;v
|
||||||
|
ersion="2.10.1"
|
||||||
|
Import-Package: sun.misc;resolution:=optional,com.google.gson.annotation
|
||||||
|
s
|
||||||
|
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.7))"
|
||||||
|
Tool: Bnd-6.4.0.202211291949
|
||||||
|
Multi-Release: true
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
artifactId=gson
|
||||||
|
groupId=com.google.code.gson
|
||||||
|
version=2.10.1
|
||||||
@@ -0,0 +1,253 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson-parent</artifactId>
|
||||||
|
<version>2.10.1</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<name>Gson</name>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>Apache-2.0</name>
|
||||||
|
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<excludeTestCompilation>**/Java17*</excludeTestCompilation>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<!--
|
||||||
|
Plugins for source generation and compilation
|
||||||
|
-->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>templating-maven-plugin</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>filtering-java-templates</id>
|
||||||
|
<goals>
|
||||||
|
<goal>filter-sources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<sourceDirectory>${basedir}/src/main/java-templates</sourceDirectory>
|
||||||
|
<outputDirectory>${project.build.directory}/generated-sources/java-templates</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>default-compile</id>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<!-- module-info.java is compiled using ModiTect -->
|
||||||
|
<exclude>module-info.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>default-testCompile</id>
|
||||||
|
<phase>test-compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>testCompile</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<testExcludes>
|
||||||
|
<exclude>${excludeTestCompilation}</exclude>
|
||||||
|
</testExcludes>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>biz.aQute.bnd</groupId>
|
||||||
|
<artifactId>bnd-maven-plugin</artifactId>
|
||||||
|
<version>6.4.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>bnd-process</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Plugins for test execution
|
||||||
|
-->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>3.0.0-M7</version>
|
||||||
|
<configuration>
|
||||||
|
<!-- Deny illegal access, this is required for ReflectionAccessTest -->
|
||||||
|
<!-- Requires Java >= 9; Important: In case future Java versions
|
||||||
|
don't support this flag anymore, don't remove it unless CI also runs with
|
||||||
|
that Java version. Ideally would use toolchain to specify that this should
|
||||||
|
run with e.g. Java 11, but Maven toolchain requirements (unlike Gradle ones)
|
||||||
|
don't seem to be portable (every developer would have to set up toolchain
|
||||||
|
configuration locally). -->
|
||||||
|
<argLine>--illegal-access=deny</argLine>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.coderplus.maven.plugins</groupId>
|
||||||
|
<artifactId>copy-rename-maven-plugin</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>pre-obfuscate-class</id>
|
||||||
|
<phase>process-test-classes</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>rename</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<fileSets>
|
||||||
|
<fileSet>
|
||||||
|
<sourceFile>${project.build.directory}/test-classes/com/google/gson/functional/EnumWithObfuscatedTest.class</sourceFile>
|
||||||
|
<destinationFile>${project.build.directory}/test-classes-obfuscated-injar/com/google/gson/functional/EnumWithObfuscatedTest.class</destinationFile>
|
||||||
|
</fileSet>
|
||||||
|
<fileSet>
|
||||||
|
<sourceFile>${project.build.directory}/test-classes/com/google/gson/functional/EnumWithObfuscatedTest$Gender.class</sourceFile>
|
||||||
|
<destinationFile>${project.build.directory}/test-classes-obfuscated-injar/com/google/gson/functional/EnumWithObfuscatedTest$Gender.class</destinationFile>
|
||||||
|
</fileSet>
|
||||||
|
</fileSets>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.github.wvengen</groupId>
|
||||||
|
<artifactId>proguard-maven-plugin</artifactId>
|
||||||
|
<version>2.6.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>obfuscate-test-class</id>
|
||||||
|
<phase>process-test-classes</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>proguard</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<obfuscate>true</obfuscate>
|
||||||
|
<injar>test-classes-obfuscated-injar</injar>
|
||||||
|
<outjar>test-classes-obfuscated-outjar</outjar>
|
||||||
|
<inFilter>**/*.class</inFilter>
|
||||||
|
<proguardInclude>${basedir}/src/test/resources/testcases-proguard.conf</proguardInclude>
|
||||||
|
<libs>
|
||||||
|
<lib>${project.build.directory}/classes</lib>
|
||||||
|
<lib>${java.home}/jmods/java.base.jmod</lib>
|
||||||
|
</libs>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>post-obfuscate-class</id>
|
||||||
|
<phase>process-test-classes</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}/test-classes/com/google/gson/functional</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${project.build.directory}/test-classes-obfuscated-outjar/com/google/gson/functional</directory>
|
||||||
|
<includes>
|
||||||
|
<include>EnumWithObfuscatedTest.class</include>
|
||||||
|
<include>EnumWithObfuscatedTest$Gender.class</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Plugins for building / modifying artifacts
|
||||||
|
-->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<!-- Use existing manifest generated by BND plugin -->
|
||||||
|
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<!-- Add module-info to JAR, see https://github.com/moditect/moditect#adding-module-descriptors-to-existing-jar-files -->
|
||||||
|
<!-- Uses ModiTect instead of separate maven-compiler-plugin executions
|
||||||
|
for better Eclipse IDE support, see https://github.com/eclipse-m2e/m2e-core/issues/393 -->
|
||||||
|
<!-- Note: For some reason this has to be executed before javadoc plugin; otherwise `javadoc:jar` goal fails
|
||||||
|
to find source files -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.moditect</groupId>
|
||||||
|
<artifactId>moditect-maven-plugin</artifactId>
|
||||||
|
<version>1.0.0.RC2</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>add-module-info</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>add-module-info</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<jvmVersion>9</jvmVersion>
|
||||||
|
<module>
|
||||||
|
<moduleInfoFile>${project.build.sourceDirectory}/module-info.java</moduleInfoFile>
|
||||||
|
</module>
|
||||||
|
<!-- Overwrite the previously generated JAR file, if any -->
|
||||||
|
<overwriteExistingFiles>true</overwriteExistingFiles>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<!-- Note: Javadoc plugin has to be run in combination with >= `package` phase,
|
||||||
|
e.g. `mvn package javadoc:javadoc`, otherwise it fails with
|
||||||
|
"Aggregator report contains named and unnamed modules" -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<excludePackageNames>com.google.gson.internal:com.google.gson.internal.bind</excludePackageNames>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>JDK17</id>
|
||||||
|
<activation>
|
||||||
|
<jdk>[17,)</jdk>
|
||||||
|
</activation>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.testRelease>17</maven.compiler.testRelease>
|
||||||
|
<excludeTestCompilation />
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
</project>
|
||||||
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 55 KiB |
|
After Width: | Height: | Size: 2.1 MiB |
|
After Width: | Height: | Size: 1.6 MiB |
|
After Width: | Height: | Size: 23 MiB |
|
After Width: | Height: | Size: 3.4 MiB |
|
After Width: | Height: | Size: 2.2 MiB |
|
After Width: | Height: | Size: 3.7 MiB |
|
After Width: | Height: | Size: 9.0 MiB |
|
After Width: | Height: | Size: 3.2 MiB |
|
After Width: | Height: | Size: 2.7 MiB |
|
After Width: | Height: | Size: 6.8 MiB |
|
After Width: | Height: | Size: 2.0 MiB |
|
After Width: | Height: | Size: 2.9 MiB |
|
After Width: | Height: | Size: 10 MiB |
|
After Width: | Height: | Size: 15 MiB |
|
After Width: | Height: | Size: 2.3 MiB |
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 2.5 MiB |
|
After Width: | Height: | Size: 9.7 MiB |
|
After Width: | Height: | Size: 2.7 MiB |
|
After Width: | Height: | Size: 2.0 MiB |
|
After Width: | Height: | Size: 557 KiB |
|
After Width: | Height: | Size: 1.8 MiB |
|
After Width: | Height: | Size: 3.6 MiB |
|
After Width: | Height: | Size: 1.0 MiB |
|
After Width: | Height: | Size: 8.9 MiB |
|
After Width: | Height: | Size: 6.7 MiB |
|
After Width: | Height: | Size: 1.9 MiB |
|
After Width: | Height: | Size: 2.7 MiB |
|
After Width: | Height: | Size: 10 MiB |
|
After Width: | Height: | Size: 15 MiB |
|
After Width: | Height: | Size: 2.2 MiB |
|
After Width: | Height: | Size: 1.3 MiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 47 KiB |
@@ -0,0 +1,28 @@
|
|||||||
|
public enum API
|
||||||
|
{
|
||||||
|
IMDB_TOP_MOVIES("https://raw.githubusercontent.com/alura-cursos/imersao-java-2-api/main/TopMovies.json", new ExtratorDeConteudoDoIMDB()),
|
||||||
|
IMDB_TOP_TVS("https://raw.githubusercontent.com/alura-cursos/imersao-java-2-api/main/TopTVs.json", new ExtratorDeConteudoDoIMDB()),
|
||||||
|
IMDB_MOST_POPULAR_MOVIES("https://raw.githubusercontent.com/alura-cursos/imersao-java-2-api/main/MostPopularMovies.json", new ExtratorDeConteudoDoIMDB()),
|
||||||
|
IMDB_MOST_POPULAR_TVS("https://raw.githubusercontent.com/alura-cursos/imersao-java-2-api/main/MostPopularTVs.json", new ExtratorDeConteudoDoIMDB()),
|
||||||
|
NASA("https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY&start_date=2022-06-12&end_date=2022-06-14", new ExtratorDeConteudoDaNasa()),
|
||||||
|
LINGUAGENS("https://alura-linguagens-simaswilliam2.fly.dev/linguagens", new ExtratorDeConteudoLinguagens());
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
private ExtratorDeConteudo extratorDeConteudo;
|
||||||
|
|
||||||
|
API(String url, ExtratorDeConteudo extratorDeConteudo)
|
||||||
|
{
|
||||||
|
this.url = url;
|
||||||
|
this.extratorDeConteudo = extratorDeConteudo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl()
|
||||||
|
{
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExtratorDeConteudo getExtrator()
|
||||||
|
{
|
||||||
|
return extratorDeConteudo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class App
|
||||||
|
{
|
||||||
|
public static void main(String[] args) throws Exception
|
||||||
|
{
|
||||||
|
limparTerminal();
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
int op = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
System.out.println(FormataTerminal.formatar("Selecione a API desejada para gerar as figurinhas: ",new String[]{FormataTerminal.TEXTO_CIANO}));
|
||||||
|
System.out.println(FormataTerminal.formatar("1",new String[]{FormataTerminal.TEXTO_CIANO}) + " - TopMovies IMDB");
|
||||||
|
System.out.println(FormataTerminal.formatar("2",new String[]{FormataTerminal.TEXTO_CIANO}) + " - TopTVs IMDB");
|
||||||
|
System.out.println(FormataTerminal.formatar("3",new String[]{FormataTerminal.TEXTO_CIANO}) + " - MostPopularMovies IMDB");
|
||||||
|
System.out.println(FormataTerminal.formatar("4",new String[]{FormataTerminal.TEXTO_CIANO}) + " - MostPopularTVs IMDB");
|
||||||
|
System.out.println(FormataTerminal.formatar("5",new String[]{FormataTerminal.TEXTO_CIANO}) + " - Nasa");
|
||||||
|
System.out.println(FormataTerminal.formatar("6",new String[]{FormataTerminal.TEXTO_CIANO}) + " - Linguagens");
|
||||||
|
System.out.println(FormataTerminal.formatar("0",new String[]{FormataTerminal.TEXTO_CIANO}) + " - Sair");
|
||||||
|
System.out.print(FormataTerminal.formatar("Escolha uma opção: ",new String[]{FormataTerminal.TEXTO_CIANO}));
|
||||||
|
|
||||||
|
op = scanner.nextInt();
|
||||||
|
|
||||||
|
switch(op)
|
||||||
|
{
|
||||||
|
case 0: break;
|
||||||
|
case 1: gerarFigurinhas(API.IMDB_TOP_MOVIES,scanner); break;
|
||||||
|
case 2: gerarFigurinhas(API.IMDB_TOP_TVS,scanner); break;
|
||||||
|
case 3: gerarFigurinhas(API.IMDB_MOST_POPULAR_MOVIES,scanner); break;
|
||||||
|
case 4: gerarFigurinhas(API.IMDB_MOST_POPULAR_TVS,scanner); break;
|
||||||
|
case 5: gerarFigurinhas(API.NASA,scanner); break;
|
||||||
|
case 6: gerarFigurinhas(API.LINGUAGENS,scanner); break;
|
||||||
|
default: System.out.println("Opção inválida!");
|
||||||
|
}
|
||||||
|
|
||||||
|
limparTerminal();
|
||||||
|
}while(op!=0);
|
||||||
|
|
||||||
|
scanner.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void limparTerminal() throws Exception
|
||||||
|
{
|
||||||
|
if (System.getProperty("os.name").contains("Windows"))
|
||||||
|
{
|
||||||
|
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Runtime.getRuntime().exec("clear");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void gerarFigurinhas(API api, Scanner scanner) throws Exception
|
||||||
|
{
|
||||||
|
limparTerminal();
|
||||||
|
String url = api.getUrl();
|
||||||
|
ExtratorDeConteudo extrator = api.getExtrator();
|
||||||
|
|
||||||
|
if(url!=null)
|
||||||
|
{
|
||||||
|
ClienteHttp http = new ClienteHttp();
|
||||||
|
String json = http.buscarDados(url);
|
||||||
|
|
||||||
|
// Extrair só os dados que interessam (Título, poster, classificação)
|
||||||
|
List<Conteudo> listaDeConteudos = extrator.extrairConteudos(json);
|
||||||
|
|
||||||
|
//Exibir e manipular os dados.
|
||||||
|
for (Conteudo conteudo : listaDeConteudos)
|
||||||
|
{
|
||||||
|
System.out.println(FormataTerminal.formatar(conteudo.titulo(), new String[]{FormataTerminal.NEGRITO,FormataTerminal.TEXTO_AMARELO}));
|
||||||
|
|
||||||
|
String urlImagem = conteudo.urlImagem();
|
||||||
|
System.out.print(FormataTerminal.formatar("Imagem: ", new String[]{FormataTerminal.NEGRITO,FormataTerminal.TEXTO_VERMELHO}));
|
||||||
|
System.out.println(FormataTerminal.formatar(urlImagem, new String[]{FormataTerminal.NEGRITO,FormataTerminal.TEXTO_CIANO}));
|
||||||
|
System.out.println("");
|
||||||
|
|
||||||
|
InputStream inputStream = new URL(urlImagem).openStream();
|
||||||
|
|
||||||
|
|
||||||
|
GeradoraDeFigurinhas geradoraDeFigurinhas = new GeradoraDeFigurinhas();
|
||||||
|
geradoraDeFigurinhas.cria(inputStream, conteudo.titulo().replace(":", " -") +".png", conteudo.titulo());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Geração concluída!");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.net.http.HttpResponse.BodyHandlers;
|
||||||
|
|
||||||
|
public class ClienteHttp
|
||||||
|
{
|
||||||
|
public String buscarDados(String url)
|
||||||
|
{
|
||||||
|
String body = "";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
URI endereco = URI.create(url);
|
||||||
|
|
||||||
|
HttpClient client = HttpClient.newHttpClient();
|
||||||
|
HttpRequest request = HttpRequest.newBuilder(endereco).GET().build();
|
||||||
|
|
||||||
|
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
|
||||||
|
body = response.body();
|
||||||
|
}
|
||||||
|
catch (IOException | InterruptedException e)
|
||||||
|
{
|
||||||
|
throw new ClienteHttpException("Falha ao consultar a API");
|
||||||
|
}
|
||||||
|
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
public class ClienteHttpException extends RuntimeException
|
||||||
|
{
|
||||||
|
public ClienteHttpException(String mensagem)
|
||||||
|
{
|
||||||
|
super(mensagem);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
public record Conteudo(String titulo, String urlImagem)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ExtratorDeConteudo
|
||||||
|
{
|
||||||
|
List<Conteudo> extrairConteudos(String json);
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ExtratorDeConteudoDaNasa implements ExtratorDeConteudo
|
||||||
|
{
|
||||||
|
|
||||||
|
public List<Conteudo> extrairConteudos(String json)
|
||||||
|
{
|
||||||
|
MyJsonParser parser = new MyJsonParser();
|
||||||
|
List<Map<String,String>> listaDeAtributos = parser.parse(json, new String[]{"title","url"});
|
||||||
|
|
||||||
|
return listaDeAtributos.stream().map(atributos->
|
||||||
|
new Conteudo(atributos.get("title"), atributos.get("url"))
|
||||||
|
).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ExtratorDeConteudoDoIMDB implements ExtratorDeConteudo
|
||||||
|
{
|
||||||
|
public List<Conteudo> extrairConteudos(String json)
|
||||||
|
{
|
||||||
|
MyJsonParser parser = new MyJsonParser();
|
||||||
|
List<Map<String,String>> listaDeAtributos = parser.parse(json, new String[]{"title","image"});
|
||||||
|
|
||||||
|
return listaDeAtributos.stream().map(atributos->
|
||||||
|
new Conteudo(atributos.get("title"), atributos.get("image"))
|
||||||
|
).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ExtratorDeConteudoLinguagens implements ExtratorDeConteudo
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Conteudo> extrairConteudos(String json)
|
||||||
|
{
|
||||||
|
MyJsonParser parser = new MyJsonParser();
|
||||||
|
List<Map<String,String>> listaDeAtributos = parser.parse(json, new String[]{"title","image"});
|
||||||
|
|
||||||
|
return listaDeAtributos.stream().map(atributos->
|
||||||
|
new Conteudo(atributos.get("title"), atributos.get("image"))
|
||||||
|
).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
public class FormataTerminal
|
||||||
|
{
|
||||||
|
public static final String NEGRITO = "\u001b[1m";
|
||||||
|
public static final String ITALICO = "\u001b[3m";
|
||||||
|
public static final String SUBLINHADO = "\u001b[4m";
|
||||||
|
public static final String PISCANDO = "\u001b[5m";
|
||||||
|
public static final String INVERTIDO = "\u001b[7m";
|
||||||
|
public static final String RISCADO = "\u001b[9m";
|
||||||
|
|
||||||
|
public static final String TEXTO_PRETO = "\u001b[30m";
|
||||||
|
public static final String TEXTO_VERMELHO = "\u001b[31m";
|
||||||
|
public static final String TEXTO_VERDE = "\u001b[32m";
|
||||||
|
public static final String TEXTO_AMARELO = "\u001b[33m";
|
||||||
|
public static final String TEXTO_AZUL = "\u001b[34m";
|
||||||
|
public static final String TEXTO_MAGENTA = "\u001b[35m";
|
||||||
|
public static final String TEXTO_CIANO = "\u001b[36m";
|
||||||
|
public static final String TEXTO_BRANCO = "\u001b[37m";
|
||||||
|
|
||||||
|
public static final String FUNDO_PRETO = "\u001b[40m";
|
||||||
|
public static final String FUNDO_VERMELHO = "\u001b[41m";
|
||||||
|
public static final String FUNDO_VERDE = "\u001b[42m";
|
||||||
|
public static final String FUNDO_AMARELO = "\u001b[43m";
|
||||||
|
public static final String FUNDO_AZUL = "\u001b[44m";
|
||||||
|
public static final String FUNDO_MAGENTA = "\u001b[45m";
|
||||||
|
public static final String FUNDO_CIANO = "\u001b[46m";
|
||||||
|
public static final String FUNDO_BRANCO = "\u001b[47m";
|
||||||
|
|
||||||
|
public static String formatar(String texto, String[] formatos)
|
||||||
|
{
|
||||||
|
String retorno = "";
|
||||||
|
for (String formato : formatos)
|
||||||
|
{
|
||||||
|
retorno += formato;
|
||||||
|
}
|
||||||
|
retorno+=texto;
|
||||||
|
retorno+="\u001b[m";
|
||||||
|
|
||||||
|
return retorno;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
public class GeradoraDeFigurinhas
|
||||||
|
{
|
||||||
|
public void cria(InputStream inputStream, String nomeArquivo, String texto) throws Exception
|
||||||
|
{
|
||||||
|
texto = texto.toUpperCase();
|
||||||
|
|
||||||
|
// leitura da imagem
|
||||||
|
BufferedImage imagemOriginal = ImageIO.read(inputStream);
|
||||||
|
|
||||||
|
String[] partes = texto.split(":");
|
||||||
|
if(partes.length == 1)
|
||||||
|
{
|
||||||
|
partes = texto.split(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
int fontSize = obterTamanhoFonte(partes,(Graphics2D)imagemOriginal.getGraphics(),imagemOriginal.getWidth()-40);
|
||||||
|
int alturaLinha = obterTamanhoLinha(partes,(Graphics2D)imagemOriginal.getGraphics(),fontSize);
|
||||||
|
int espacoLegenda = partes.length * alturaLinha + 20;
|
||||||
|
|
||||||
|
// cria nova imagem em memória com transparência e com tamanho novo
|
||||||
|
int largura = imagemOriginal.getWidth();
|
||||||
|
int altura = imagemOriginal.getHeight();
|
||||||
|
int novaAltura = altura + espacoLegenda;
|
||||||
|
|
||||||
|
BufferedImage novaImagem = new BufferedImage(largura, novaAltura, BufferedImage.TRANSLUCENT);
|
||||||
|
|
||||||
|
//copiar a imagem original para nova imagem (em memória)
|
||||||
|
Graphics2D graphics = (Graphics2D) novaImagem.getGraphics();
|
||||||
|
graphics.drawImage(imagemOriginal, 0, 0, null);
|
||||||
|
|
||||||
|
// Configurar a fonte e cor
|
||||||
|
Font fonte = new Font("Comic Sans MS", Font.BOLD, fontSize);
|
||||||
|
graphics.setColor(Color.RED);
|
||||||
|
graphics.setFont(fonte);
|
||||||
|
|
||||||
|
int[] espacamentosSuperiores = new int[partes.length];
|
||||||
|
int[] espacamentosLaterais = new int[partes.length];
|
||||||
|
|
||||||
|
//Calculando espaçamento para centralizar o texto
|
||||||
|
for (int i=0; i<partes.length;i++)
|
||||||
|
{
|
||||||
|
FontMetrics fontMetrics = graphics.getFontMetrics();
|
||||||
|
Rectangle2D rectangle = fontMetrics.getStringBounds(partes[i], graphics);
|
||||||
|
double larguraTexto = rectangle.getWidth();
|
||||||
|
double alturaTexto = rectangle.getHeight();
|
||||||
|
int espacamentoEsquerdo = ((largura-(int)larguraTexto)/2);
|
||||||
|
//int espacamentoSuperior = novaAltura- (int)alturaLinha * (partes.length-i);
|
||||||
|
int espacamentoSuperior = novaAltura -20 - (int)alturaTexto * i;//- (int)alturaTexto * (partes.length-i);
|
||||||
|
|
||||||
|
espacamentosSuperiores[i] = espacamentoSuperior;
|
||||||
|
espacamentosLaterais[i] = espacamentoEsquerdo;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escrever uma frase na nova imagem
|
||||||
|
for (int i=0; i<partes.length;i++)
|
||||||
|
{
|
||||||
|
graphics.drawString(partes[i], espacamentosLaterais[i], espacamentosSuperiores[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Verifica se o diretório de saída existe. Se não existir, cria o diretório.
|
||||||
|
File diretorioSaida = new File("saida");
|
||||||
|
if(!diretorioSaida.exists())
|
||||||
|
{
|
||||||
|
diretorioSaida.mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escrever a nova imagem em um arquivo
|
||||||
|
ImageIO.write(novaImagem, "png", new File("saida/" + nomeArquivo));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int obterTamanhoFonte(String[] partes, Graphics2D graphics, int larguraMaxima)
|
||||||
|
{
|
||||||
|
boolean parar = false;
|
||||||
|
int fontSize = 1;
|
||||||
|
|
||||||
|
while(!parar)
|
||||||
|
{
|
||||||
|
// Configurar a fonte e cor
|
||||||
|
Font fonte = new Font("Comic Sans MS", Font.BOLD, fontSize);
|
||||||
|
graphics.setFont(fonte);
|
||||||
|
|
||||||
|
//Calculando espaçamento para centralizar o texto
|
||||||
|
for (int i=0; i<partes.length;i++)
|
||||||
|
{
|
||||||
|
FontMetrics fontMetrics = graphics.getFontMetrics();
|
||||||
|
Rectangle2D rectangle = fontMetrics.getStringBounds(partes[i], graphics);
|
||||||
|
double larguraTexto = rectangle.getWidth();
|
||||||
|
if(larguraTexto>larguraMaxima)
|
||||||
|
{
|
||||||
|
parar = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fontSize++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fontSize-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int obterTamanhoLinha(String[] partes, Graphics2D graphics, int fontSize)
|
||||||
|
{
|
||||||
|
double alturaLinha = 0;
|
||||||
|
// Configurar a fonte e cor
|
||||||
|
Font fonte = new Font("Comic Sans MS", Font.BOLD, fontSize);
|
||||||
|
graphics.setFont(fonte);
|
||||||
|
|
||||||
|
//Calculando espaçamento para centralizar o texto
|
||||||
|
for (int i=0; i<partes.length;i++)
|
||||||
|
{
|
||||||
|
FontMetrics fontMetrics = graphics.getFontMetrics();
|
||||||
|
Rectangle2D rectangle = fontMetrics.getStringBounds(partes[i], graphics);
|
||||||
|
double alturaTexto = rectangle.getHeight();
|
||||||
|
if(alturaTexto>alturaLinha)
|
||||||
|
{
|
||||||
|
alturaLinha = alturaTexto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) alturaLinha;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
|
//Classe desenvolvida para fazer o parse das imagens da nasa
|
||||||
|
//Sugestão encontrada em https://stackoverflow.com/questions/2591098/how-to-parse-json-in-java
|
||||||
|
public class MyJsonParser
|
||||||
|
{
|
||||||
|
public List<Map<String,String>> parse(String json, String[] fields)
|
||||||
|
{
|
||||||
|
List<Map<String,String>> mapList = new ArrayList<>();
|
||||||
|
|
||||||
|
int index =0;
|
||||||
|
int oldIndex = 0;
|
||||||
|
String jSonPart="";
|
||||||
|
|
||||||
|
index = json.indexOf("[", 0)+1;
|
||||||
|
oldIndex = json.indexOf("[", 0)+1;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
index = json.indexOf("}", oldIndex);
|
||||||
|
if(index>=0 && oldIndex>=0)
|
||||||
|
{
|
||||||
|
jSonPart = json.substring(oldIndex, index+1);
|
||||||
|
JsonObject jsonObject = new JsonParser().parse(jSonPart).getAsJsonObject();
|
||||||
|
|
||||||
|
Map<String,String> mapItem = new HashMap<>();
|
||||||
|
for (String field : fields)
|
||||||
|
{
|
||||||
|
mapItem.put(field, jsonObject.get(field).getAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
mapList.add(mapItem);
|
||||||
|
}
|
||||||
|
oldIndex = json.indexOf("{", index);
|
||||||
|
}while(index>=0 && oldIndex>=0);
|
||||||
|
|
||||||
|
return mapList;
|
||||||
|
}
|
||||||
|
}
|
||||||