Skip to content

Instantly share code, notes, and snippets.

@sheimi
sheimi / HelloJNI-modified.java
Created November 9, 2014 05:01
code in blog.sheimi.me: hello JNI
//Here is HelloJNI.java
public class HelloJNI {
static {
try {
Class c = HelloJNI.class;
URL location =
c.getProtectionDomain().getCodeSource().getLocation();
ZipFile zf = new ZipFile(location.getPath());
// libhellojni.so is put in the lib folder
@sheimi
sheimi / crawl.java
Last active August 29, 2015 14:09
code in blog.sheimi.me: 2012-05-13-hadoop-source-code-01 (1)
// code snippet in nutch
Injector injector = new Injector(getConf());
Generator generator = new Generator(getConf());
Fetcher fetcher = new Fetcher(getConf());
ParseSegment parseSegment = new ParseSegment(getConf());
CrawlDb crawlDbTool = new CrawlDb(getConf());
LinkDb linkDbTool = new LinkDb(getConf());
injector.inject(crawlDb, rootUrlDir);
int i;
@sheimi
sheimi / crawl.java
Created November 9, 2014 05:23
code in blog.sheimi.me: 2012-05-13-hadoop-source-code-01 (2)
linkDbTool.invert(linkDb, segments, true, true, false); // invert links
if (solrUrl != null) {
// index, dedup & merge
FileStatus[] fstats = fs.listStatus(segments, HadoopFSUtil.getPassDirectoriesFilter(fs));
SolrIndexer indexer = new SolrIndexer(getConf());
indexer.indexSolr(solrUrl, crawlDb, linkDb,
Arrays.asList(HadoopFSUtil.getPaths(fstats)));
SolrDeleteDuplicates dedup = new SolrDeleteDuplicates();
dedup.setConf(getConf());
@sheimi
sheimi / injector.java
Created November 9, 2014 05:27
code in blog.sheimi.me: 2012-05-17-source-code-02 (1) injector
if (LOG.isInfoEnabled()) {
LOG.info("Injector: Converting injected urls to crawl db entries.");
}
JobConf sortJob = new NutchJob(getConf());
sortJob.setJobName("inject " + urlDir);
FileInputFormat.addInputPath(sortJob, urlDir);
sortJob.setMapperClass(InjectMapper.class);
FileOutputFormat.setOutputPath(sortJob, tempDir);
sortJob.setOutputFormat(SequenceFileOutputFormat.class);
@sheimi
sheimi / injector.java
Created November 9, 2014 05:28
code in blog.sheimi.me: 2012-05-17-source-code-02 (2) injector
public static JobConf createJob(Configuration config, Path crawlDb)
throws IOException {
Path newCrawlDb = new Path(crawlDb,
Integer.toString(new Random().nextInt(Integer.MAX_VALUE)));
JobConf job = new NutchJob(config);
job.setJobName("crawldb " + crawlDb);
Path current = new Path(crawlDb, CURRENT_NAME);
if (FileSystem.get(job).exists(current)) {
@sheimi
sheimi / injector.java
Created November 9, 2014 05:29
code in blog.sheimi.me: 2012-05-17-source-code-02 (3) injector
public static void install(JobConf job, Path crawlDb) throws IOException {
Path newCrawlDb = FileOutputFormat.getOutputPath(job);
FileSystem fs = new JobClient(job).getFs();
Path old = new Path(crawlDb, "old");
Path current = new Path(crawlDb, CURRENT_NAME);
if (fs.exists(current)) {
if (fs.exists(old)) fs.delete(old, true);
fs.rename(current, old);
}
fs.mkdirs(crawlDb);
@sheimi
sheimi / CVJNI.java
Created November 9, 2014 05:31
code in blog.sheimi.me: 2012-09-05-a-summary-of-using-jni (1)
// CVJNI.java
import java.io.*;
public class CVJNI {
//Load jni library
static {
try {
System.loadLibrary("cvjni");
} catch (Exception e) {
e.printStackTrace();
@sheimi
sheimi / cvjni.cpp
Created November 9, 2014 05:32
code in blog.sheimi.me: 2012-09-05-a-summary-of-using-jni (2)
//cvjni.cpp
#include "cvjni.h"
#include <opencv2/opencv.hpp>
#include <vector>
#include <iostream>
using namespace std;
using namespace cv;
/*
@sheimi
sheimi / Makefile
Created November 9, 2014 05:33
code in blog.sheimi.me: 2012-09-05-a-summary-of-using-jni (3)
# Makefile
# FOR MAC
CC=g++
SEARCH_LIB=-lopencv_core -lopencv_highgui
INCLUDE=-I/usr/local/include -I$(JAVA_INCLUDE)
LIBRARY=-L/usr/local/lib
FLAGS= -m64 -dynamiclib -fPIC
OUT=libcvjni.jnilib
SRC=cvjni.cpp
@sheimi
sheimi / test.sh
Created November 9, 2014 05:34
code in blog.sheimi.me: 2012-09-05-a-summary-of-using-jni (4)
g++ -m64 -shared -fPIC cvjni.cpp /usr/local/lib/libopencv_core.so \
/usr/local/lib/libopencv_highgui.so -o libcvjni.so \
-I/usr/local/include -I/usr/lib/jvm/jdk1.6.0_35/include \
-I/usr/lib/jvm/jdk1.6.0_35/include/linux