From 0dce040adc46b7d3cdffb384b6d5d46007438747 Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Thu, 19 Jan 2017 10:55:00 +0100 Subject: [PATCH] Correzioni nomi classi e path --- {sql => resources}/towns.csv | 0 .../ConnectionFactory.java | 0 .../DistrictDao.java} | 0 src/it/noah/crawler/io/DirFilter.java | 13 -- src/it/noah/crawler/io/FileUtils.java | 189 ------------------ 5 files changed, 202 deletions(-) rename {sql => resources}/towns.csv (100%) rename src/it/noah/crawler/{persistence => dao}/ConnectionFactory.java (100%) rename src/it/noah/crawler/{persistence/DistrictAccess.java => dao/DistrictDao.java} (100%) delete mode 100644 src/it/noah/crawler/io/DirFilter.java delete mode 100644 src/it/noah/crawler/io/FileUtils.java diff --git a/sql/towns.csv b/resources/towns.csv similarity index 100% rename from sql/towns.csv rename to resources/towns.csv diff --git a/src/it/noah/crawler/persistence/ConnectionFactory.java b/src/it/noah/crawler/dao/ConnectionFactory.java similarity index 100% rename from src/it/noah/crawler/persistence/ConnectionFactory.java rename to src/it/noah/crawler/dao/ConnectionFactory.java diff --git a/src/it/noah/crawler/persistence/DistrictAccess.java b/src/it/noah/crawler/dao/DistrictDao.java similarity index 100% rename from src/it/noah/crawler/persistence/DistrictAccess.java rename to src/it/noah/crawler/dao/DistrictDao.java diff --git a/src/it/noah/crawler/io/DirFilter.java b/src/it/noah/crawler/io/DirFilter.java deleted file mode 100644 index b2b1625..0000000 --- a/src/it/noah/crawler/io/DirFilter.java +++ /dev/null @@ -1,13 +0,0 @@ -package it.noah.crawler.io; - -import java.io.File; -import java.io.FilenameFilter; - -public class DirFilter implements FilenameFilter { - - @Override - public boolean accept(File dir, String name) { - return new File(dir, name).isDirectory(); - } - -} diff --git a/src/it/noah/crawler/io/FileUtils.java b/src/it/noah/crawler/io/FileUtils.java deleted file mode 100644 index fdab1f4..0000000 --- a/src/it/noah/crawler/io/FileUtils.java +++ /dev/null @@ -1,189 +0,0 @@ -package it.noah.crawler.io; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.OutputStream; -import java.io.PushbackInputStream; -import java.io.Reader; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import java.util.StringTokenizer; - -/** - * Classe per la gestione dei file - * - * @author Fabio Scotto di Santolo - * @since 22/12/2016 - */ -public class FileUtils { - - public static int countBytes(String path) throws IOException { - InputStream in = new FileInputStream(path); - int total = 0; - - try { - while (in.read() != -1) { - total++; - } - } finally { - if (in != null) { - in.close(); - } - } - - return total; - } - - public static void translateByte(InputStream in, OutputStream out, - String[] args) throws IOException { - byte from = (byte) args[0].charAt(0); - byte to = (byte) args[1].charAt(0); - int b = 0; - - try { - while ((b = in.read()) != -1) { - out.write(b == from ? to : b); - } - } finally { - if (in != null) { - in.close(); - } - if (out != null) { - out.close(); - } - } - } - - public static int countSpace(String path) throws IOException { - Reader in = new FileReader(path); - int ch = 0; - int spaces = 0; - - try { - while ((ch = in.read()) != -1) { - if (Character.isWhitespace((char) ch)) { - spaces++; - } - } - } finally { - if (in != null) { - in.close(); - } - } - - return spaces; - } - - public static void copy(String src, String dest) throws IOException { - File file = new File(src); - File copy = new File(dest); - InputStream in = new FileInputStream(file); - OutputStream out = new FileOutputStream(copy); - int c = 0; - - try { - if (file.exists()) { - while ((c = in.read()) != -1) { - out.write(c); - } - } - } finally { - if (in != null) { - in.close(); - } - if (out != null) { - out.close(); - } - } - } - - public static List tokens(String path, String delimiter) - throws IOException { - File file = new File(path); - InputStream in = new FileInputStream(file); - PushbackInputStream pis = new PushbackInputStream(in); - List line = new ArrayList(); - int c = 0; - - try { - if (file.exists()) { - while ((c = pis.read()) != -1) { - String str = new String(); - pis.unread(c); - while ((c = pis.read()) != '\n') { - str += (char) c; - } - - StringTokenizer token = new StringTokenizer(str, delimiter); - - while (token.hasMoreTokens()) { - line.add(token.nextToken()); - } - } - } - } finally { - if (in != null) { - in.close(); - } - } - - return line; - } - - public static Properties getProperties(String path) throws IOException { - Properties prop = new Properties(); - List list = tokens(path, "="); - int i = 0; - - while (i < list.size()) { - prop.setProperty(list.get(i), list.get(i + 1)); - i = i + 2; - } - - return prop; - } - - public static String[] fileNameFilter(String dirPath) { - File dir = new File(dirPath); - return dir.list(new DirFilter()); - } - - public static void serialize(Object obj, String path) throws IOException { - FileOutputStream fileOut = new FileOutputStream(path); - ObjectOutputStream out = new ObjectOutputStream(fileOut); - - try { - out.writeObject(obj); - } finally { - if (out != null) { - out.close(); - } - } - } - - @SuppressWarnings("unchecked") - public static T deserialize(String path, Class type) - throws IOException, ClassNotFoundException { - FileInputStream fileIn = new FileInputStream(path); - ObjectInputStream out = new ObjectInputStream(fileIn); - T ret = null; - - try { - ret = (T) out.readObject(); - } finally { - if (out != null) { - out.close(); - } - } - - return ret; - } - -}