import org.apache.poi.hssf.record.WriteProtectRecord;
import org.apache.poi.hssf.record.common.UnicodeString;
import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.ss.formula.EvaluationWorkbook.ExternalName;
import org.apache.poi.ss.formula.EvaluationWorkbook.ExternalSheet;
import org.apache.poi.ss.formula.EvaluationWorkbook.ExternalSheetRange;
WriteAccessRecord waccess = getWriteAccess();
/* WriteProtectRecord wprotect =*/ getWriteProtect();
frec.setReadOnly((short)1);
- frec.setPassword(FileSharingRecord.hashPassword(password));
+ frec.setPassword((short)CryptoFunctions.createXorVerifier1(password));
frec.setUsername(username);
waccess.setUsername(username);
}
}
}
- //this is the world's lamest "security". thanks to Wouter van Vugt for making me
- //not have to try real hard. -ACO
- public static short hashPassword(String password) {
- byte[] passwordCharacters = password.getBytes();
- int hash = 0;
- if (passwordCharacters.length > 0) {
- int charIndex = passwordCharacters.length;
- while (charIndex-- > 0) {
- hash = ((hash >> 14) & 0x01) | ((hash << 1) & 0x7fff);
- hash ^= passwordCharacters[charIndex];
- }
- // also hash with charcount
- hash = ((hash >> 14) & 0x01) | ((hash << 1) & 0x7fff);
- hash ^= passwordCharacters.length;
- hash ^= (0x8000 | ('N' << 8) | 'K');
- }
- return (short)hash;
- }
-
/**
* set the readonly flag
*
* Aggregates the drawing records and dumps the escher record hierarchy
* to the standard output.
*/
- public void dumpDrawingRecords(boolean fat) {
+ public void dumpDrawingRecords(boolean fat, PrintWriter pw) {
_sheet.aggregateDrawingRecords(_book.getDrawingManager(), false);
EscherAggregate r = (EscherAggregate) getSheet().findFirstRecordBySid(EscherAggregate.sid);
List<EscherRecord> escherRecords = r.getEscherRecords();
- PrintWriter w = new PrintWriter(System.out);
for (Iterator<EscherRecord> iterator = escherRecords.iterator(); iterator.hasNext(); ) {
EscherRecord escherRecord = iterator.next();
if (fat) {
- System.out.println(escherRecord.toString());
+ pw.println(escherRecord.toString());
} else {
- escherRecord.display(w, 0);
+ escherRecord.display(pw, 0);
}
}
- w.flush();
+ pw.flush();
}
/**
*
* @return the name of this sheet
*/
+ @SuppressWarnings("resource")
public String getSheetName() {
HSSFWorkbook wb = getWorkbook();
int idx = wb.getSheetIndex(this);
import java.io.File;
import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.nio.charset.Charset;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
*/
public class DrawingDump
{
- public static void main( String[] args ) throws IOException
- {
- NPOIFSFileSystem fs =
- new NPOIFSFileSystem(new File(args[0]));
+ public static void main( String[] args ) throws IOException {
+ OutputStreamWriter osw = new OutputStreamWriter(System.out, Charset.defaultCharset());
+ PrintWriter pw = new PrintWriter(osw);
+ NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(args[0]));
HSSFWorkbook wb = new HSSFWorkbook(fs);
try {
- System.out.println( "Drawing group:" );
+ pw.println( "Drawing group:" );
wb.dumpDrawingGroupRecords(true);
for (int sheetNum = 1; sheetNum <= wb.getNumberOfSheets(); sheetNum++)
{
- System.out.println( "Sheet " + sheetNum + ":" );
+ pw.println( "Sheet " + sheetNum + ":" );
HSSFSheet sheet = wb.getSheetAt(sheetNum - 1);
- sheet.dumpDrawingRecords(true);
+ sheet.dumpDrawingRecords(true, pw);
}
} finally {
wb.close();
+ fs.close();
}
}
}
import org.apache.poi.poifs.crypt.CryptoFunctions;\r
import org.apache.poi.poifs.crypt.HashAlgorithm;\r
import org.apache.poi.poifs.crypt.dsig.SignatureConfig;\r
+import org.apache.poi.util.HexDump;\r
import org.apache.poi.util.IOUtils;\r
import org.apache.poi.util.POILogFactory;\r
import org.apache.poi.util.POILogger;\r
\r
ByteArrayOutputStream bos = new ByteArrayOutputStream();\r
IOUtils.copy(huc.getInputStream(), bos);\r
- LOG.log(POILogger.DEBUG, "response content: ", bos.toString());\r
+ LOG.log(POILogger.DEBUG, "response content: ", HexDump.dump(bos.toByteArray(), 0, 0));\r
\r
if (!contentType.startsWith(signatureConfig.isTspOldProtocol() \r
? "application/timestamp-response"\r
assertEquals(32, info.getVerifier().getEncryptedVerifierHash().length);\r
assertEquals(CipherProvider.aes, info.getHeader().getCipherProvider()); \r
assertEquals("Microsoft Enhanced RSA and AES Cryptographic Provider", info.getHeader().getCspName());\r
+ \r
+ fs.close();\r
}\r
\r
@Test\r
assertEquals(64, info.getVerifier().getEncryptedVerifierHash().length);\r
assertEquals(CipherProvider.aes, info.getHeader().getCipherProvider()); \r
// assertEquals("Microsoft Enhanced RSA and AES Cryptographic Provider", info.getHeader().getCspName());\r
+ \r
+ fs.close();\r
}\r
}\r
package org.apache.poi.hdgf;
-import java.io.FileInputStream;
+import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LocaleUtil;
/**
* See
dir.createDocumentInputStream("VisioDocument").read(_docstream);
// Check it's really visio
- String typeString = new String(_docstream, 0, 20);
+ String typeString = new String(_docstream, 0, 20, LocaleUtil.CHARSET_1252 );
if(! typeString.equals(VISIO_HEADER)) {
throw new IllegalArgumentException("Wasn't a valid visio document, started with " + typeString);
}
* For testing only
*/
public static void main(String args[]) throws Exception {
- HDGFDiagram hdgf = new HDGFDiagram(new POIFSFileSystem(new FileInputStream(args[0])));
+ NPOIFSFileSystem pfs = new NPOIFSFileSystem(new File(args[0]));
+ HDGFDiagram hdgf = new HDGFDiagram(pfs);
hdgf.debug();
+ pfs.close();
}
}
import java.util.Hashtable;
import java.util.StringTokenizer;
+import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
*/
private void processChunkParseCommands() throws IOException {
String line;
- InputStream cpd = ChunkFactory.class.getResourceAsStream(chunkTableName);
- if(cpd == null) {
- throw new IllegalStateException("Unable to find HDGF chunk definition on the classpath - " + chunkTableName);
+ InputStream cpd = null;
+ BufferedReader inp = null;
+ try {
+ cpd = ChunkFactory.class.getResourceAsStream(chunkTableName);
+ if(cpd == null) {
+ throw new IllegalStateException("Unable to find HDGF chunk definition on the classpath - " + chunkTableName);
+ }
+
+ inp = new BufferedReader(new InputStreamReader(cpd, LocaleUtil.CHARSET_1252));
+
+ while( (line = inp.readLine()) != null ) {
+ if(line.startsWith("#")) continue;
+ if(line.startsWith(" ")) continue;
+ if(line.startsWith("\t")) continue;
+ if(line.length() == 0) continue;
+
+ // Start xxx
+ if(!line.startsWith("start")) {
+ throw new IllegalStateException("Expecting start xxx, found " + line);
+ }
+ int chunkType = Integer.parseInt(line.substring(6));
+ ArrayList<CommandDefinition> defsL = new ArrayList<CommandDefinition>();
+
+ // Data entries
+ while( ! (line = inp.readLine()).startsWith("end") ) {
+ StringTokenizer st = new StringTokenizer(line, " ");
+ int defType = Integer.parseInt(st.nextToken());
+ int offset = Integer.parseInt(st.nextToken());
+ String name = st.nextToken("\uffff").substring(1);
+
+ CommandDefinition def = new CommandDefinition(defType,offset,name);
+ defsL.add(def);
+ }
+
+ CommandDefinition[] defs = defsL.toArray(new CommandDefinition[defsL.size()]);
+
+ // Add to the hashtable
+ chunkCommandDefinitions.put(Integer.valueOf(chunkType), defs);
+ }
+ } finally {
+ if (inp != null) inp.close();
+ if (cpd != null) cpd.close();
}
-
- BufferedReader inp = new BufferedReader(new InputStreamReader(cpd));
- while( (line = inp.readLine()) != null ) {
- if(line.startsWith("#")) continue;
- if(line.startsWith(" ")) continue;
- if(line.startsWith("\t")) continue;
- if(line.length() == 0) continue;
-
- // Start xxx
- if(!line.startsWith("start")) {
- throw new IllegalStateException("Expecting start xxx, found " + line);
- }
- int chunkType = Integer.parseInt(line.substring(6));
- ArrayList<CommandDefinition> defsL = new ArrayList<CommandDefinition>();
-
- // Data entries
- while( ! (line = inp.readLine()).startsWith("end") ) {
- StringTokenizer st = new StringTokenizer(line, " ");
- int defType = Integer.parseInt(st.nextToken());
- int offset = Integer.parseInt(st.nextToken());
- String name = st.nextToken("\uffff").substring(1);
-
- CommandDefinition def = new CommandDefinition(defType,offset,name);
- defsL.add(def);
- }
-
- CommandDefinition[] defs = defsL.toArray(new CommandDefinition[defsL.size()]);
-
- // Add to the hashtable
- chunkCommandDefinitions.put(Integer.valueOf(chunkType), defs);
- }
- inp.close();
- cpd.close();
}
public int getVersion() { return version; }
import org.apache.poi.hpbf.model.qcbits.UnknownQCBit;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LocaleUtil;
/**
* Quill -> QuillSub -> CONTENTS
// all our bits
// Check first 8 bytes
- String f8 = new String(data, 0, 8);
+ String f8 = new String(data, 0, 8, LocaleUtil.CHARSET_1252);
if(! f8.equals("CHNKINK ")) {
throw new IllegalArgumentException("Expecting 'CHNKINK ' but was '"+f8+"'");
}
int offset = 0x20 + i*24;
if(data[offset] == 0x18 && data[offset+1] == 0x00) {
// Has some data
- String thingType = new String(data, offset+2, 4);
+ String thingType = new String(data, offset+2, 4, LocaleUtil.CHARSET_1252);
int optA = LittleEndian.getUShort(data, offset+6);
int optB = LittleEndian.getUShort(data, offset+8);
int optC = LittleEndian.getUShort(data, offset+10);
- String bitType = new String(data, offset+12, 4);
+ String bitType = new String(data, offset+12, 4, LocaleUtil.CHARSET_1252);
int from = (int)LittleEndian.getUInt(data, offset+16);
int len = (int)LittleEndian.getUInt(data, offset+20);
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
+import java.nio.charset.Charset;
import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.poifs.filesystem.DocumentEntry;
protected boolean hexHeader = true;
public PPTXMLDump(File ppt) throws IOException {
- NPOIFSFileSystem fs = new NPOIFSFileSystem(ppt);
-
- //read the document entry from OLE file system
- DocumentEntry entry = (DocumentEntry)fs.getRoot().getEntry(PPDOC_ENTRY);
- docstream = new byte[entry.getSize()];
- DocumentInputStream is = fs.createDocumentInputStream(PPDOC_ENTRY);
- is.read(docstream);
-
+ NPOIFSFileSystem fs = new NPOIFSFileSystem(ppt, true);
+ DocumentInputStream is = null;
+
try {
+ //read the document entry from OLE file system
+ DocumentEntry entry = (DocumentEntry)fs.getRoot().getEntry(PPDOC_ENTRY);
+ docstream = new byte[entry.getSize()];
+ is = fs.createDocumentInputStream(PPDOC_ENTRY);
+ is.read(docstream);
+ is.close();
+
entry = (DocumentEntry)fs.getRoot().getEntry(PICTURES_ENTRY);
pictstream = new byte[entry.getSize()];
is = fs.createDocumentInputStream(PICTURES_ENTRY);
is.read(pictstream);
} catch(FileNotFoundException e){
//silently catch errors if the presentation does not contain pictures
+ } finally {
+ if (is != null) is.close();
+ fs.close();
}
}
* @param out <code>Writer</code> to write out
* @throws java.io.IOException
*/
- public void dump(Writer out) throws IOException {
- this.out = out;
+ public void dump(Writer outWriter) throws IOException {
+ this.out = outWriter;
int padding = 0;
write(out, "<Presentation>" + CR, padding);
System.out.println("Dumping " + args[i]);
if (outFile){
- FileWriter out = new FileWriter(ppt.getName() + ".xml");
+ FileOutputStream fos = new FileOutputStream(ppt.getName() + ".xml");
+ OutputStreamWriter out = new OutputStreamWriter(fos, Charset.forName("UTF8"));
dump.dump(out);
out.close();
} else {
wrapper.appendChildRecord(tha);\r
\r
TextBytesAtom tba = new TextBytesAtom();\r
- tba.setText("".getBytes());\r
+ tba.setText("".getBytes(LocaleUtil.CHARSET_1252));\r
wrapper.appendChildRecord(tba);\r
\r
StyleTextPropAtom sta = new StyleTextPropAtom(1);\r
package org.apache.poi.hssf.converter;
import java.io.File;
-import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
* Where infile is an input .xls file ( Word 97-2007) which will be rendered
* as XSL FO into outfile
*/
- public static void main( String[] args )
- {
- if ( args.length < 2 )
- {
- System.err
- .println( "Usage: ExcelToFoConverter <inputFile.xls> <saveTo.xml>" );
+ public static void main( String[] args ) throws Exception {
+ if ( args.length < 2 ) {
+ System.err.println( "Usage: ExcelToFoConverter <inputFile.xls> <saveTo.xml>" );
return;
}
System.out.println( "Converting " + args[0] );
System.out.println( "Saving output to " + args[1] );
- try
- {
- Document doc = ExcelToHtmlConverter.process( new File( args[0] ) );
-
- FileWriter out = new FileWriter( args[1] );
- DOMSource domSource = new DOMSource( doc );
- StreamResult streamResult = new StreamResult( out );
-
- TransformerFactory tf = TransformerFactory.newInstance();
- Transformer serializer = tf.newTransformer();
- // TODO set encoding from a command argument
- serializer.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
- serializer.setOutputProperty( OutputKeys.INDENT, "no" );
- serializer.setOutputProperty( OutputKeys.METHOD, "xml" );
- serializer.transform( domSource, streamResult );
- out.close();
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
+
+ Document doc = ExcelToHtmlConverter.process( new File( args[0] ) );
+
+ DOMSource domSource = new DOMSource( doc );
+ StreamResult streamResult = new StreamResult( new File(args[1]) );
+
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer serializer = tf.newTransformer();
+ // TODO set encoding from a command argument
+ serializer.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
+ serializer.setOutputProperty( OutputKeys.INDENT, "no" );
+ serializer.setOutputProperty( OutputKeys.METHOD, "xml" );
+ serializer.transform( domSource, streamResult );
}
/**
XMLHelper.getDocumentBuilderFactory().newDocumentBuilder()
.newDocument() );
excelToHtmlConverter.processWorkbook( workbook );
- return excelToHtmlConverter.getDocument();
+ Document doc = excelToHtmlConverter.getDocument();
+ workbook.close();
+ return doc;
}
private final FoDocumentFacade foDocumentFacade;
}
String text = characterRun.text();
- if ( text.getBytes().length == 0 )
- continue;
+ if ( text.isEmpty() ) continue;
if ( characterRun.isSpecialCharacter() )
{
}
}
- if ( text.getBytes()[0] == FIELD_BEGIN_MARK )
+ if ( text.charAt(0) == FIELD_BEGIN_MARK )
{
if ( wordDocument instanceof HWPFDocument )
{
continue;
}
- if ( text.getBytes()[0] == FIELD_SEPARATOR_MARK )
+ if ( text.charAt(0) == FIELD_SEPARATOR_MARK )
{
// shall not appear without FIELD_BEGIN_MARK
continue;
}
- if ( text.getBytes()[0] == FIELD_END_MARK )
+ if ( text.charAt(0) == FIELD_END_MARK )
{
// shall not appear without FIELD_BEGIN_MARK
continue;
CharacterRun characterRun = range.getCharacterRun( c );
String text = characterRun.text();
- if ( text.getBytes().length == 0 )
- continue;
+ if ( text.isEmpty() ) continue;
- final byte firstByte = text.getBytes()[0];
+ final char firstByte = text.charAt(0);
if ( firstByte == FIELD_BEGIN_MARK )
{
int[] nested = tryDeadField_lookupFieldSeparatorEnd(
continue;
}
- if ( text.getBytes()[0] == FIELD_END_MARK )
+ if ( firstByte == FIELD_END_MARK )
{
if ( endMark != -1 )
{
package org.apache.poi.hwpf.converter;
import java.io.File;
-import java.io.FileWriter;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
* Where infile is an input .doc file ( Word 97-2007) which will be rendered
* as XSL-FO into outfile
*/
- public static void main( String[] args )
- {
+ public static void main( String[] args ) throws Exception {
if ( args.length < 2 )
{
- System.err
- .println( "Usage: WordToFoConverter <inputFile.doc> <saveTo.fo>" );
+ System.err.println( "Usage: WordToFoConverter <inputFile.doc> <saveTo.fo>" );
return;
}
System.out.println( "Converting " + args[0] );
System.out.println( "Saving output to " + args[1] );
- try
- {
- Document doc = WordToFoConverter.process( new File( args[0] ) );
-
- FileWriter out = new FileWriter( args[1] );
- DOMSource domSource = new DOMSource( doc );
- StreamResult streamResult = new StreamResult( out );
- TransformerFactory tf = TransformerFactory.newInstance();
- Transformer serializer = tf.newTransformer();
- // TODO set encoding from a command argument
- serializer.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
- serializer.setOutputProperty( OutputKeys.INDENT, "yes" );
- serializer.transform( domSource, streamResult );
- out.close();
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
+ Document doc = WordToFoConverter.process( new File( args[0] ) );
+
+ DOMSource domSource = new DOMSource( doc );
+ StreamResult streamResult = new StreamResult( new File( args[1] ) );
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer serializer = tf.newTransformer();
+ // TODO set encoding from a command argument
+ serializer.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
+ serializer.setOutputProperty( OutputKeys.INDENT, "yes" );
+ serializer.transform( domSource, streamResult );
}
static Document process( File docFile ) throws Exception
import static org.apache.poi.hwpf.converter.AbstractWordUtils.TWIPS_PER_INCH;
import java.io.File;
-import java.io.FileWriter;
import java.util.List;
import java.util.Stack;
* Where infile is an input .doc file ( Word 95-2007) which will be rendered
* as HTML into outfile
*/
- public static void main( String[] args )
+ public static void main( String[] args ) throws Exception
{
if ( args.length < 2 )
{
System.out.println( "Converting " + args[0] );
System.out.println( "Saving output to " + args[1] );
- try
- {
- Document doc = WordToHtmlConverter.process( new File( args[0] ) );
-
- FileWriter out = new FileWriter( args[1] );
- DOMSource domSource = new DOMSource( doc );
- StreamResult streamResult = new StreamResult( out );
-
- TransformerFactory tf = TransformerFactory.newInstance();
- Transformer serializer = tf.newTransformer();
- // TODO set encoding from a command argument
- serializer.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
- serializer.setOutputProperty( OutputKeys.INDENT, "yes" );
- serializer.setOutputProperty( OutputKeys.METHOD, "html" );
- serializer.transform( domSource, streamResult );
- out.close();
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
+
+ Document doc = WordToHtmlConverter.process( new File( args[0] ) );
+
+ DOMSource domSource = new DOMSource( doc );
+ StreamResult streamResult = new StreamResult( new File(args[1]) );
+
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer serializer = tf.newTransformer();
+ // TODO set encoding from a command argument
+ serializer.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
+ serializer.setOutputProperty( OutputKeys.INDENT, "yes" );
+ serializer.setOutputProperty( OutputKeys.METHOD, "html" );
+ serializer.transform( domSource, streamResult );
}
static Document process( File docFile ) throws Exception
package org.apache.poi.hwpf.converter;
import java.io.File;
-import java.io.FileWriter;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.util.List;
* Where infile is an input .doc file ( Word 95-2007) which will be rendered
* as plain text into outfile
*/
- public static void main( String[] args )
- {
+ public static void main( String[] args ) throws Exception {
if ( args.length < 2 )
{
- System.err
- .println( "Usage: WordToTextConverter <inputFile.doc> <saveTo.txt>" );
+ System.err.println( "Usage: WordToTextConverter <inputFile.doc> <saveTo.txt>" );
return;
}
System.out.println( "Converting " + args[0] );
System.out.println( "Saving output to " + args[1] );
- try
- {
- Document doc = WordToTextConverter.process( new File( args[0] ) );
-
- FileWriter out = new FileWriter( args[1] );
- DOMSource domSource = new DOMSource( doc );
- StreamResult streamResult = new StreamResult( out );
-
- TransformerFactory tf = TransformerFactory.newInstance();
- Transformer serializer = tf.newTransformer();
- // TODO set encoding from a command argument
- serializer.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
- serializer.setOutputProperty( OutputKeys.INDENT, "no" );
- serializer.setOutputProperty( OutputKeys.METHOD, "text" );
- serializer.transform( domSource, streamResult );
- out.close();
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
+
+ Document doc = WordToTextConverter.process( new File( args[0] ) );
+
+ DOMSource domSource = new DOMSource( doc );
+ StreamResult streamResult = new StreamResult( new File( args[1] ) );
+
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer serializer = tf.newTransformer();
+ // TODO set encoding from a command argument
+ serializer.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
+ serializer.setOutputProperty( OutputKeys.INDENT, "no" );
+ serializer.setOutputProperty( OutputKeys.METHOD, "text" );
+ serializer.transform( domSource, streamResult );
}
static Document process( File docFile ) throws Exception
package org.apache.poi.hdgf.chunks;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
-public final class TestChunks extends TestCase {
+import org.junit.Test;
+
+public final class TestChunks {
public static final byte[] data_a = new byte[] { 70, 0, 0, 0,
-1, -1, -1, -1, 2, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 68, 0, 0, 0, 0, 0,
0, 0, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0
};
-
+
+ @Test
public void testChunkHeaderA() throws Exception {
- ChunkFactory cf = new ChunkFactory(11);
ChunkHeader h =
ChunkHeader.createChunkHeader(11, data_a, 0);
assertTrue(header.hasTrailer());
assertTrue(header.hasSeparator());
}
- public void testChunkHeaderB() throws Exception {
- ChunkFactory cf = new ChunkFactory(11);
+
+ @Test
+ public void testChunkHeaderB() throws Exception {
ChunkHeader h =
ChunkHeader.createChunkHeader(11, data_b, 0);
assertTrue(header.hasSeparator());
}
- public void testOneChunk() throws Exception {
+ @Test
+ public void testOneChunk() throws Exception {
ChunkFactory cf = new ChunkFactory(11);
cf.createChunk(data_a, 0);
cf.createChunk(data_b, 0);
assertEquals("0", chunk.commandDefinitions[1].getName());
}
- public void testAnotherChunk() throws Exception {
+ @Test
+ public void testAnotherChunk() throws Exception {
ChunkFactory cf = new ChunkFactory(11);
// Go for the 2nd chunk in the stream
assertEquals("0", chunk.commandDefinitions[1].getName());
}
- public void testManyChunks() throws Exception {
+ @Test
+ public void testManyChunks() throws Exception {
ChunkFactory cf = new ChunkFactory(11);
Chunk chunk;
int offset = 0;