Skip to content

Instantly share code, notes, and snippets.

@arn-e
arn-e / env_struct.c
Created January 22, 2013 01:32
env_struct.c
struct env_type
{
int *(*GetIntArrayElements)(struct jintArray);
int *(*ReleaseIntArrayElements)(struct jintArray, int *native_array);
};
@arn-e
arn-e / jni_array_conversion.c
Created January 22, 2013 01:29
JNI array conversion
JNIEXPORT jint JNICALL Java_ShortWeight_matrixWeight
(JNIEnv * env, jobject jobj, jintArray matrix_values, jint rows, jint columns)
{
jint *matrix_ptr;
matrix_ptr = (*env)->GetIntArrayElements(env, matrix_values, NULL);
(*env)->ReleaseIntArrayElements(env, matrix_values, matrix_ptr, 0);
}
@arn-e
arn-e / env_create_env_structure.c
Created January 22, 2013 01:35
env_create_env_structure.c
struct env_type create_env_structure()
{
struct env_type env_struct, *env_ptr;
env_struct.GetIntArrayElements = &GetIntArrayElementsFunc;
env_struct.ReleaseIntArrayElements = &ReleaseIntArrayElementsFunc;
return env_struct;
}
@arn-e
arn-e / env_functions_getintarrayelements.c
Last active December 11, 2015 11:08
env_functions_getintarrayelements.c
int *GetIntArrayElementsFunc(struct jintArray jvm_array)
{
int size = jvm_array.size;
int *native_array = malloc(size * sizeof(int));
for (int i = 0; i < size; i ++){
native_array[i] = jvm_array.elements[i];
}
return native_array;
}
@arn-e
arn-e / jintArray_struct.c
Last active December 11, 2015 11:08
jintArray_struct.c
#include <stdio.h>
#include <stdlib.h>
struct jintArray
{
int size;
int *elements;
};
@arn-e
arn-e / poorly_handled_checked_exception.java
Last active December 11, 2015 03:59
(poorly) handled checked exception - Java
public class FileReaderTest {
public static void main(String[] args) {
String filename = "./public/non_existent.file";
try {
List<String> allLines = Files.readAllLines(Paths.get(filename), Charset.defaultCharset());
for ( String i : allLines ) {
System.out.println(i);
}
@arn-e
arn-e / unhandled_checked_exception.java
Last active December 11, 2015 03:59
unhandled checked exception java
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.List;
import java.nio.file.Paths;
public class FileReaderTest {
public static void main(String[] args) {
String filename = "./public/index.html";
@arn-e
arn-e / handled_checked_exception.java
Last active December 11, 2015 03:59
handled checked exception in Java
public class FileReaderTest {
public static void main(String[] args) {
String filename = "./public/index.html";
try {
List<String> allLines = Files.readAllLines(Paths.get(filename), Charset.defaultCharset());
for ( String i : allLines ) {
System.out.println(i);
}
@arn-e
arn-e / checked_exception_unhandled.java
Created January 15, 2013 20:22
unhandled checked exception in Java
import java.io.FileInputStream;
import java.io.File;
public class FileReaderTest {
public static void main(String[] args) {
File newFile = new File("./public/sample_file.text");
FileInputStream fileStream = new FileInputStream(newFile);
}
}
@arn-e
arn-e / checked_exception_handling.java
Created January 15, 2013 20:21
checked exception handling in Java
import java.io.FileInputStream;
import java.io.File;
import java.io.FileNotFoundException;
public class FileReaderTest {
public static void main(String[] args) {
File newFile = new File("./public/sample_file.text");
try {