Skip to content

Commit

Permalink
add load method for overload
Browse files Browse the repository at this point in the history
  • Loading branch information
shin285 committed May 2, 2017
1 parent f42c706 commit 94fc82d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kr.co.shineware.ds.aho_corasick;

import java.io.File;
import java.util.*;

import kr.co.shineware.ds.aho_corasick.model.AhoCorasickNode;
Expand All @@ -20,6 +21,13 @@ public void load(String filename){
root.load(filename);
}

public void save(File file){
root.save(file);
}
public void load(File file){
root.load(file);
}

public void put(String keys,V value){
this.put(keys.toCharArray(), value);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package kr.co.shineware.ds.aho_corasick.model;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.io.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

Expand Down Expand Up @@ -75,13 +69,24 @@ public void save(String filename) {
ObjectOutputStream dos;
try {
dos = new ObjectOutputStream(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(filename))));
// dos = new ObjectOutputStream(new BufferedOutputStream((new FileOutputStream(filename))));
write(dos,true);
dos.close();
} catch (Exception e) {
e.printStackTrace();
}
}

public void save(File file) {
ObjectOutputStream dos;
try {
dos = new ObjectOutputStream(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file))));
write(dos,true);
dos.close();
} catch (Exception e) {
e.printStackTrace();
}
}

private void write(ObjectOutputStream dos,boolean isRoot) throws Exception {
if(!isRoot){
dos.writeChar(this.getKey());
Expand All @@ -106,6 +111,18 @@ public void load(String filename) {
e.printStackTrace();
}
}

public void load(File file){
ObjectInputStream dis;
try {
dis = new ObjectInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file))));
load(dis,true);
dis.close();
} catch (Exception e) {
e.printStackTrace();
}
}

@SuppressWarnings("unchecked")
private void load(ObjectInputStream dis,boolean isRoot) throws Exception {
if(!isRoot){
Expand Down

0 comments on commit 94fc82d

Please sign in to comment.