1. hwpx 개념잡기
2. 한글 문서 파일 구조 5.0 제공하는 구조요약
3. PrvText
스트림에는 미리보기 텍스트가 유니코드 문자열로 저장됨.
4. 00n-S190106-example.hwpx에서 PrvText.txt 파일 형식
5. PrvText.txt 출력
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class PrvText {
public static void main(String[] args) {
try {
//파일 객체 생성
File file = new File
("/Users/ssu/Desktop/00n-S190106-example/Preview/PrvText.txt");
//입력 스트림 생성
FileReader filereader = new FileReader(file);
int singleCh = 0;
while ((singleCh = filereader.read()) != -1) {
System.out.print((char)singleCh);
}
filereader.close();
} catch (FileNotFoundException e) {
//TODO: handle exception
} catch(IOException e) {
System.out.println(e);
}
}
}
6. Section0.xml 출력
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class SectionXml {
public static void main(String[] args) {
try {
//파일 객체 생성
File file = new File
("/Users/ssu/Desktop/00n-S190106-example/Contents/section0.xml");
//입력 스트림 생성
FileReader filereader = new FileReader(file);
int singleCh = 0;
while ((singleCh = filereader.read()) != -1) {
System.out.print((char)singleCh);
}
filereader.close();
} catch (FileNotFoundException e) {
//TODO: handle exception
} catch(IOException e) {
System.out.println(e);
}
}
}
7. Section0.xml to JSON
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.json.JSONObject;
import org.json.XML;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
public class SectionXml2Json {
public static void main(String[] args) {
try(InputStream inputStream = new FileInputStream
(new File("/Users/ssu/Desktop/00n-S190106-example/Contents/section0.xml"))) {
String xml = IOUtils.toString(inputStream);
JSONObject jObject = XML.toJSONObject(xml);
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
Object json = mapper.readValue(jObject.toString(), Object.class);
String output = mapper.writeValueAsString(json);
System.out.println(output);
} catch (Exception e) {
e.printStackTrace();
}
}
}
8 .00n-S190106-example.zip 데이터 출력
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.Scanner;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class ZipReader {
public static void main(String[] args) throws IOException {
ZipFile ZipFile =
new ZipFile("/Users/ssu/Desktop/00n-S190106-example.zip");
Enumeration<? extends ZipEntry> entries = ZipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
InputStream stream = ZipFile.getInputStream(entry);
InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
Scanner inputStream = new Scanner(reader);
inputStream.nextLine();
while (inputStream.hasNext()) {
String data = inputStream.nextLine(); // Gets a whole line
System.out.println(data);
}
inputStream.close();
stream.close();
}
ZipFile.close();
}
}