package org.riverock.proxy; import java.io.*; import com.mongodb.*; /** * User: SergeMaslyukov * Date: 02.11.2009 * Time: 0:26:51 */ public class ReadFileContent { public static void main(String[] args) throws IOException { String file = "file-7762970531535664141.dat"; FileInputStream fis = new FileInputStream( new File(file)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] bytes = new byte[0x200]; int count; while ((count=fis.read(bytes))!=-1) { baos.write(bytes, 0, count); } fis.close(); final String content = baos.toString("8859_1"); System.out.println("content.length() = " + content.length()); Mongo m = new Mongo(); DB db = m.getDB( "proxy" ); DBCollection pages = db.getCollection("pages"); BasicDBObject query = new BasicDBObject(); String url = "url"; query.put("url", url); DBCursor cur = pages.find(query); if (cur.hasNext()) { System.out.println(" - skip "); return; } BasicDBObject doc = new BasicDBObject(); doc.put("url", url); doc.put("date", new java.util.Date()); doc.put("title", "New title"); doc.put("content", content); pages.insert(doc); System.out.println(" - stored"); } }