Skip to content
Snippets Groups Projects
Commit 18477305 authored by Bergony 's avatar Bergony
Browse files

Class Arquivos,ArqWeb,ArqCsv

parent 743efcd2
No related branches found
No related tags found
No related merge requests found
......@@ -3,5 +3,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER"/>
<classpathentry kind="lib" path="lib/opencsv-4.6.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
File added
source diff could not be displayed: it is too large. Options to address this: view the blob.
File added
package br.ufrn.imd.controle;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JPopupMenu.Separator;
import br.ufrn.imd.modelo.ArqCsv;
import br.ufrn.imd.modelo.ArqWeb;
public class ControladorArquivo {
private String arquivo = "C:\\Users\\PPGECO\\Desktop\\Bergony\\Fake\\FakeNews\\FakeNews\\src\\Docs\\boatos.csv";
private BufferedReader buffer = null;
private FileReader in;
public ControladorArquivo(){
}
public void abrirArquivo() throws arquivoException {
try {
in = new FileReader(arquivo);
} catch (FileNotFoundException e) {
throw new arquivoException(e);
}
}
public int dataSetSize() throws IOException {
int count = 0;
String out;
setBuffer(new BufferedReader(in));
while((out = buffer.readLine()) != null)
{
count++;
}
buffer.close();
count -= 2;
return count;
}
public String lerLinha(int linha, int coluna) throws IOException {
int count = 0;
setBuffer(new BufferedReader(in));
String out = buffer.readLine();
out = buffer.readLine();
String divisor = ",";
String[] dividi = null;
while(count <= linha)
{
dividi = out.split(divisor);
if((out = buffer.readLine()) == null)
{
throw new arquivoException("ID Fora do DataSet");
}
count++;
}
if(coluna <= 1)
{
return dividi[coluna];
}
if(coluna == 3)
{
dividi = out.split(",https//");
return dividi[1];
}
if(coluna == 4)
{
dividi = out.split("html,");
return dividi[1];
}
return "-1";
}
public String getArquivo() {
return arquivo;
}
public void setArquivo(String arquivo) {
this.arquivo = arquivo;
}
public BufferedReader getBuffer() {
return buffer;
}
public void setBuffer(BufferedReader buffer) {
this.buffer = buffer;
}
public FileReader getIn() {
return in;
}
public void setIn(FileReader in) {
this.in = in;
}
private ArqCsv csv;
private ArqWeb web;
private String[] listCsv;
private String[] listWeb;
}
package br.ufrn.imd.controle;
import br.ufrn.imd.modelo.Noticia;
public class ControladorNoticia {
private Noticia noticia;
private boolean fake;
private String formatada = "";
public
}
......@@ -4,12 +4,8 @@ import java.io.FileNotFoundException;
public class arquivoException extends FileNotFoundException {
/**
*
*/
private static final long serialVersionUID = 1L;
public arquivoException(Exception e) {
super(e.getMessage());
// TODO Auto-generated constructor stub
......
package br.ufrn.imd.modelo;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import com.opencsv.CSVReader;
import br.ufrn.imd.controle.arquivoException;
public class ArqCsv implements Arquivo {
private String destino = "C:\\Users\\PPGECO\\Desktop\\Bergony\\Fake\\FakeNews\\FakeNews\\src\\Docs\\boatos.csv";
CSVReader leitor;
public ArqCsv(String destino, CSVReader leitor) throws FileNotFoundException {
this.destino = destino;
try {
this.leitor = new CSVReader(new FileReader(destino));
} catch (arquivoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void abrir() throws arquivoException {
try {
this.leitor = new CSVReader(new FileReader(destino));
} catch (FileNotFoundException e) {
throw new arquivoException("Arquivo nao Encontrado");
}
}
@Override
public void fechar() throws arquivoException {
// TODO Auto-generated method stub
try {
leitor.close();
} catch (IOException e) {
// TODO Auto-generated catch block
throw new arquivoException(e);
}
}
@Override
public String ler(int x) throws IOException {
// TODO Auto-generated method stub
int count = 0;
String[] s;
while((s = leitor.readNext()) != null) {
if(x <= count) {
return s[count];
}
}
return "Valor fora";
}
}
package br.ufrn.imd.modelo;
public class ArqWeb implements Arquivo {
private String url;
@Override
public void abrir() {
// TODO Auto-generated method stub
}
@Override
public void fechar() {
// TODO Auto-generated method stub
}
@Override
public String ler(int x) {
return url;
// TODO Auto-generated method stub
}
}
package br.ufrn.imd.modelo;
import java.io.IOException;
import br.ufrn.imd.controle.arquivoException;
public interface Arquivo {
public void abrir() throws arquivoException;
public void fechar() throws arquivoException;
public String ler(int x) throws IOException;
}
package br.ufrn.imd.visao;
import java.io.IOException;
import br.ufrn.imd.controle.ControladorArquivo;
public class Principal {
public static void main(String[] args) throws IOException {
System.out.println("Out");
ControladorArquivo ca = new ControladorArquivo();
ca.abrirArquivo();
int out1 = ca.dataSetSize();
System.out.println("Saida "+ out1);
ca.abrirArquivo();
System.out.println("Saida "+ ca.lerLinha(0, 1));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment