本文整理汇总了Java中happy.coding.io.FileIO.readAsList方法的典型用法代码示例。如果您正苦于以下问题:Java FileIO.readAsList方法的具体用法?Java FileIO.readAsList怎么用?Java FileIO.readAsList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类happy.coding.io.FileIO
的用法示例。
在下文中一共展示了FileIO.readAsList方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: crawl_web_pages
import happy.coding.io.FileIO; //导入方法依赖的package包/类
public void crawl_web_pages() throws Exception
{
String filePath = "./src/main/resources/mtime.txt";
List<String> urls = FileIO.readAsList(filePath);
for (String url : urls)
{
String html = URLReader.read(url);
Document doc = Jsoup.parse(html);
String name = doc.select("span[property=v:itemreviewed]").text();
name = Strings.filterWebString(name, '_');
String dirPath = dir + name + "/";
FileIO.makeDirectory(dirPath);
FileIO.writeString(dirPath + name + ".html", html);
}
}
示例2: getAllUsers
import happy.coding.io.FileIO; //导入方法依赖的package包/类
public static void getAllUsers() throws Exception {
String filePath = FileIO.getResource("dvd.ciao.txt");
List<String> urls = FileIO.readAsList(filePath);
String dir = Systems.getDesktop() + "dvd.ciao.co.uk\\";
String userFile = dir + "users.txt";
Map<String, String> userMap = new HashMap<>();
for (String url : urls) {
// each category
String[] data = url.split(": ");
String category = data[0];
String dirPath = FileIO.makeDirPath(dir, category);
// users
String userPath = dirPath + "users.txt";
List<String> users = FileIO.readAsList(userPath);
for (String line : users) {
String[] d = line.split(",");
userMap.put(d[0], d[1]);
}
}
FileIO.writeMap(userFile, userMap);
}
示例3: load_proxy
import happy.coding.io.FileIO; //导入方法依赖的package包/类
protected void load_proxy() throws Exception
{
proxy = new HashMap<>();
String path = FileIO.getResource("proxy.txt");
List<String> lines = FileIO.readAsList(path);
for (String line : lines)
{
String[] data = line.split(":");
String host = data[0];
int port = Integer.parseInt(data[1]);
proxy.put(host, port);
}
hosts = new ArrayList<>(proxy.keySet());
}
示例4: run_category_ratings
import happy.coding.io.FileIO; //导入方法依赖的package包/类
/**
* Concate all the dvd ratings about the products in a specific category
*
* @param url
* @throws Exception
*/
public void run_category_ratings(String url) throws Exception {
String[] data = url.split(": ");
String category = data[0];
String catPath = FileIO.makeDirPath(desktop, domain, category);
File Dir = new File(catPath);
File[] prodDirs = Dir.listFiles();
int tk = prodDirs.length;
String ratingFile = catPath + "movie-ratings.txt";
FileIO.deleteFile(ratingFile);
for (int k = 0; k < tk; k++) {
File prodDir = prodDirs[k];
// for each product
String productID = prodDir.getName();
if (productID.equals("webPages"))
continue;
if (!prodDir.isDirectory())
continue;
Logs.debug("{}: {} ({}/{})", new Object[] { category, productID,
(k + 1), tk });
String prodPath = FileIO.makeDirPath(catPath, productID);
String dvdPath = prodPath + "dvd-ratings.txt";
if (!FileIO.exist(dvdPath))
continue;
List<String> dvd_ratings = FileIO.readAsList(dvdPath);
FileIO.writeList(ratingFile, dvd_ratings, null, true);
}
}
示例5: getAllRatings
import happy.coding.io.FileIO; //导入方法依赖的package包/类
public static void getAllRatings() throws Exception {
String filePath = FileIO.getResource("dvd.ciao.txt");
List<String> urls = FileIO.readAsList(filePath);
String dir = Systems.getDesktop() + "dvd.ciao.co.uk\\";
String ratingFile = dir + "ratings.txt";
String reviewFile = dir + "review-ratings.txt";
FileIO.deleteFile(ratingFile);
FileIO.deleteFile(reviewFile);
for (String url : urls) {
// each category
String[] data = url.split(": ");
String category = data[0];
String dirPath = FileIO.makeDirPath(dir, category);
// ratings
String ratingPath = dirPath + "ratings.txt";
List<String> ratings = FileIO.readAsList(ratingPath);
FileIO.writeList(ratingFile, ratings, null, true);
// reviews
String reviewPath = dirPath + "review-ratings.txt";
List<String> reviews = FileIO.readAsList(reviewPath);
FileIO.writeList(reviewFile, reviews, null, true);
}
}
示例6: crawl_data
import happy.coding.io.FileIO; //导入方法依赖的package包/类
public static void crawl_data() throws Exception
{
String filePath = FileIO.getResource("gewara.txt");
List<String> urls = FileIO.readAsList(filePath);
String[] tasks = { "comments" };
int nd = 4;
for (String task : tasks)
{
Logs.info("Current task: " + task);
for (int i = 0; i < urls.size(); i += nd)
{
Thread[] tds = new Thread[nd];
boolean flag = false;
for (int j = 0; j < nd; j++)
{
if (i + j >= urls.size())
{
flag = true;
break;
}
String url = urls.get(i + j).trim();
tds[j] = new Thread(new GewaraCrawler(url, task, i + j + 1));
tds[j].start();
}
for (Thread td : tds)
{
if (td != null) td.join();
}
if (flag) break;
}
}
}
示例7: crawl_data
import happy.coding.io.FileIO; //导入方法依赖的package包/类
public static void crawl_data() throws Exception
{
String filePath = FileIO.getResource("douban.txt");
List<String> urls = FileIO.readAsList(filePath);
String[] tasks = { "reviews" };
int nd = 4;
for (String task : tasks)
{
Logs.info("Current task: " + task);
for (int i = 0; i < urls.size(); i += nd)
{
Thread[] tds = new Thread[nd];
boolean flag = false;
for (int j = 0; j < nd; j++)
{
if (i + j >= urls.size())
{
flag = true;
break;
}
String url = urls.get(i + j).trim();
tds[j] = new Thread(new DoubanCrawler(url, task, i + j + 1));
tds[j].start();
}
for (Thread td : tds)
{
if (td != null) td.join();
}
if (flag) break;
}
}
}
示例8: crawl_data
import happy.coding.io.FileIO; //导入方法依赖的package包/类
public static void crawl_data() throws Exception {
if (Debug.OFF) {
// home page
CiaoCrawler cc = new CiaoCrawler();
cc.run_home_page();
return;
}
String sourceFile = "users.txt"; // "dvd.ciao.txt"
String filePath = FileIO.getResource(sourceFile);
List<String> urls = FileIO.readAsList(filePath);
String[] tasks = { "users" };
int nd = 8;
for (String task : tasks) {
Logs.info("Current task: " + task);
for (int i = 0; i < urls.size(); i += nd) {
Thread[] tds = new Thread[nd];
boolean flag = false;
for (int j = 0; j < nd; j++) {
if (i + j >= urls.size()) {
flag = true;
break;
}
String url = urls.get(i + j).trim();
tds[j] = new Thread(new CiaoCrawler(url, task, i + j + 1));
tds[j].start();
}
for (Thread td : tds) {
if (td != null)
td.join();
}
if (flag)
break;
}
}
}
示例9: run_products
import happy.coding.io.FileIO; //导入方法依赖的package包/类
public void run_products(String url) throws Exception {
String[] data = url.split(": ");
String category = data[0];
// String link = data[1];
String dirPath = FileIO.makeDirPath(desktop, domain, category);
List<String> links = FileIO.readAsList(dirPath + "movies.txt");
int tk = links.size();
for (int k = 0; k < tk; k++) {
String link = links.get(k);
String[] d = link.split("::");
String id = d[0];
String name = d[1];
String productLink = d[2];
int idx = productLink.lastIndexOf("/");
String p1 = productLink.substring(0, idx) + "/Reviews";
String reviewLink = p1 + productLink.substring(idx);
// create folder
String path = FileIO.makeDirectory(dirPath, id);
// product page
String html = null;
String pagePath = path + id + ".html";
if (!FileIO.exist(pagePath)) {
html = read_url(productLink);
FileIO.deleteFile(path + name + ".html");
FileIO.writeString(pagePath, html);
}
// product reviews
// get first page anyway to identify the maximum pages
path = FileIO.makeDirectory(path, "Reviews");
String reviewPath = path + "page_1.html";
if (FileIO.exist(reviewPath)) {
html = FileIO.readAsString(reviewPath);
} else {
html = read_url(reviewLink);
FileIO.writeString(reviewPath, html);
}
Logs.debug(category + ": " + id + " (" + (k + 1) + "/" + tk + ")"
+ ": page " + 1);
Document doc = Jsoup.parse(html);
Elements nav = doc.select("div#Pagination");
if (!nav.isEmpty()) {
int maxPage = 1;
Elements last = nav.select("li.last");
if (!last.isEmpty())
maxPage = Integer.parseInt(last.first().text()); // more
// than
// 11
// pages
else
maxPage = Integer.parseInt(nav.select("li").last().text()); // less
// or
// equal
// 11
// pages
for (int i = 2; i <= maxPage; i++) {
String filePath = path + "page_" + i + ".html";
if (FileIO.exist(filePath))
continue;
reviewLink = reviewLink + "/Start/" + ((i - 1) * 15);
html = read_url(reviewLink);
FileIO.writeString(filePath, html);
Logs.debug(category + ": " + id + " (" + (k + 1) + "/" + tk
+ ")" + ": page " + i + "/" + maxPage);
}
}
}
}
示例10: parseCategoryPages
import happy.coding.io.FileIO; //导入方法依赖的package包/类
public static void parseCategoryPages() throws Exception {
String filePath = FileIO.getResource("dvd.ciao.txt");
List<String> urls = FileIO.readAsList(filePath);
String dir = Systems.getDesktop() + "dvd.ciao.co.uk\\";
for (String url : urls) {
// each category
String[] data = url.split(": ");
String category = data[0];
String dirCate = FileIO.makeDirPath(dir, category);
String dirPath = FileIO.makeDirPath(dir, category, "webPages");
// clear
FileIO.deleteFile(dirCate + "movies.txt");
File dirs = new File(dirPath);
for (File f : dirs.listFiles()) {
// each web page
String html = FileIO.readAsString(dirPath + f.getName());
Document doc = Jsoup.parse(html);
Logs.debug(category + ": " + f.getName());
List<String> movies = new ArrayList<>();
Elements products = doc.select("td.prodInfo");
for (Element product : products) {
// each product
Element prod = product.select("p.prodName").first();
String name = prod.text();
String link = prod.select("a").first().attr("href");
String id = link.substring(link.lastIndexOf("_") + 1);
// number of user reviews
prod = product.select("p.prodRating").first();
String cnt = prod.select(".userReviewsCount").text()
.replace("(", "").replace(")", "");
int count = 0;
if (!cnt.isEmpty())
count = Integer.parseInt(cnt);
// do not consider movies without any reviews
if (count > 0) {
String movie = id + "::" + name + "::" + link;
movies.add(movie);
}
}
FileIO.writeList(dirCate + "movies.txt", movies, null, true);
}
}
}
示例11: getAllTrust
import happy.coding.io.FileIO; //导入方法依赖的package包/类
public static void getAllTrust() throws Exception {
Map<String, String> users = new HashMap<>();
List<String> userLines = FileIO.readAsList(FileIO
.getResource("users.txt"));
for (String line : userLines) {
String[] data = line.split(",");
users.put(data[1], data[0]);
}
String usersPath = FileIO.makeDirPath(desktop, domain,
"users.ciao.co.uk");
FileIO.deleteFile(usersPath + "trust.txt");
File dir = new File(usersPath);
File[] files = dir.listFiles();
for (int i = 0, n = files.length; i < n; i++) {
// for each user
File userFile = files[i];
final String userID = userFile.getName();
String html = null;
Document doc = null;
List<String> friends = new ArrayList<>();
File[] pages = userFile.listFiles();
for (int j = 0, m = pages.length; j < m; j++) {
// for each trust page
File file = pages[j];
String name = file.getName();
if (name.startsWith("friends")) {
html = FileIO.readAsString(file.getPath());
doc = Jsoup.parse(html);
Element trustTable = doc.select("form table.trust").first();
Elements trs = trustTable.select("tbody tr");
for (Element tr : trs) {
Element td = tr.select("td").get(1);
Element a = td.select("a").first();
String link = a.attr("href");
if (users.containsKey(link)) {
friends.add(users.get(link));
}
}
}
}
FileIO.writeList(usersPath + "trust.txt", friends,
new Converter<String, String>() {
@Override
public String transform(String friend) {
return userID + "," + friend + ",1";
}
}, true);
}
}
示例12: parseReviewPages
import happy.coding.io.FileIO; //导入方法依赖的package包/类
public static void parseReviewPages() throws Exception {
String filePath = FileIO.getResource("dvd.ciao.txt");
List<String> urls = FileIO.readAsList(filePath);
String dir = Systems.getDesktop() + "dvd.ciao.co.uk\\";
for (String url : urls) {
// each category
String[] data = url.split(": ");
String category = data[0];
String dirCate = FileIO.makeDirPath(dir, category);
File dirs = new File(dirCate);
for (File f : dirs.listFiles()) {
// each product folder
if (f.getName().equals("webPages"))
continue;
if (!f.isDirectory())
continue;
String prodPath = FileIO.makeDirPath(dirCate, f.getName());
String revwPath = FileIO.makeDirPath(prodPath, "Reviews");
List<String> reviews = new ArrayList<>();
File reviewDirs = new File(revwPath);
for (File rf : reviewDirs.listFiles()) {
// each review page
String html = FileIO.readAsString(rf.getPath());
Document doc = Jsoup.parse(html);
Elements es = doc.select("div.m-shortReviewSnippet");
for (Element e : es) {
Element a = e.select(
"p.m-shet-review-title a.ReviewTitle").first();
if (a == null)
continue; // some reviews do not have specific link
// to detailed contents
// url
String link = a.attr("href");
int idx = link.lastIndexOf("_");
String id = link.substring(idx + 1);
reviews.add(id + "::" + link);
}
}
FileIO.writeList(prodPath + "reviews.txt", reviews, null, false);
}
}
}