Remove dependency on commons-codec
This commit is contained in:
parent
b788fb13ff
commit
f502a447a3
18
pom.xml
18
pom.xml
@ -58,6 +58,13 @@
|
|||||||
<url>http://www.apache.org/</url>
|
<url>http://www.apache.org/</url>
|
||||||
</organization>
|
</organization>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>1.6</java.version>
|
||||||
|
<project.build.sourceEncoding>utf8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-logging</groupId>
|
<groupId>commons-logging</groupId>
|
||||||
@ -73,18 +80,7 @@
|
|||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>commons-codec</groupId>
|
|
||||||
<artifactId>commons-codec</artifactId>
|
|
||||||
<version>1.10</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-core</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
<version>1.3</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
@ -43,7 +43,6 @@ import java.util.NoSuchElementException;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
|
||||||
import org.apache.poi.EncryptedDocumentException;
|
import org.apache.poi.EncryptedDocumentException;
|
||||||
import org.apache.poi.POIDocument;
|
import org.apache.poi.POIDocument;
|
||||||
import org.apache.poi.ddf.EscherBSERecord;
|
import org.apache.poi.ddf.EscherBSERecord;
|
||||||
@ -1938,101 +1937,6 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a picture to the workbook.
|
|
||||||
*
|
|
||||||
* @param pictureData The bytes of the picture
|
|
||||||
* @param format The format of the picture. One of <code>PICTURE_TYPE_*</code>
|
|
||||||
*
|
|
||||||
* @return the index to this picture (1 based).
|
|
||||||
* @see #PICTURE_TYPE_WMF
|
|
||||||
* @see #PICTURE_TYPE_EMF
|
|
||||||
* @see #PICTURE_TYPE_PICT
|
|
||||||
* @see #PICTURE_TYPE_PNG
|
|
||||||
* @see #PICTURE_TYPE_JPEG
|
|
||||||
* @see #PICTURE_TYPE_DIB
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("fallthrough")
|
|
||||||
@Override
|
|
||||||
public int addPicture(byte[] pictureData, int format)
|
|
||||||
{
|
|
||||||
initDrawings();
|
|
||||||
|
|
||||||
byte[] uid = DigestUtils.md5(pictureData);
|
|
||||||
EscherBlipRecord blipRecord;
|
|
||||||
int blipSize;
|
|
||||||
short escherTag;
|
|
||||||
switch (format) {
|
|
||||||
case PICTURE_TYPE_WMF:
|
|
||||||
// remove first 22 bytes if file starts with magic bytes D7-CD-C6-9A
|
|
||||||
// see also http://de.wikipedia.org/wiki/Windows_Metafile#Hinweise_zur_WMF-Spezifikation
|
|
||||||
if (LittleEndian.getInt(pictureData) == 0x9AC6CDD7) {
|
|
||||||
byte picDataNoHeader[] = new byte[pictureData.length-22];
|
|
||||||
System.arraycopy(pictureData, 22, picDataNoHeader, 0, pictureData.length-22);
|
|
||||||
pictureData = picDataNoHeader;
|
|
||||||
}
|
|
||||||
// fall through
|
|
||||||
case PICTURE_TYPE_EMF:
|
|
||||||
EscherMetafileBlip blipRecordMeta = new EscherMetafileBlip();
|
|
||||||
blipRecord = blipRecordMeta;
|
|
||||||
blipRecordMeta.setUID(uid);
|
|
||||||
blipRecordMeta.setPictureData(pictureData);
|
|
||||||
// taken from libre office export, it won't open, if this is left to 0
|
|
||||||
blipRecordMeta.setFilter((byte)-2);
|
|
||||||
blipSize = blipRecordMeta.getCompressedSize() + 58;
|
|
||||||
escherTag = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
EscherBitmapBlip blipRecordBitmap = new EscherBitmapBlip();
|
|
||||||
blipRecord = blipRecordBitmap;
|
|
||||||
blipRecordBitmap.setUID( uid );
|
|
||||||
blipRecordBitmap.setMarker( (byte) 0xFF );
|
|
||||||
blipRecordBitmap.setPictureData( pictureData );
|
|
||||||
blipSize = pictureData.length + 25;
|
|
||||||
escherTag = (short) 0xFF;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
blipRecord.setRecordId((short) (EscherBlipRecord.RECORD_ID_START + format));
|
|
||||||
switch (format)
|
|
||||||
{
|
|
||||||
case PICTURE_TYPE_EMF:
|
|
||||||
blipRecord.setOptions(HSSFPictureData.MSOBI_EMF);
|
|
||||||
break;
|
|
||||||
case PICTURE_TYPE_WMF:
|
|
||||||
blipRecord.setOptions(HSSFPictureData.MSOBI_WMF);
|
|
||||||
break;
|
|
||||||
case PICTURE_TYPE_PICT:
|
|
||||||
blipRecord.setOptions(HSSFPictureData.MSOBI_PICT);
|
|
||||||
break;
|
|
||||||
case PICTURE_TYPE_PNG:
|
|
||||||
blipRecord.setOptions(HSSFPictureData.MSOBI_PNG);
|
|
||||||
break;
|
|
||||||
case PICTURE_TYPE_JPEG:
|
|
||||||
blipRecord.setOptions(HSSFPictureData.MSOBI_JPEG);
|
|
||||||
break;
|
|
||||||
case PICTURE_TYPE_DIB:
|
|
||||||
blipRecord.setOptions(HSSFPictureData.MSOBI_DIB);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Unexpected picture format: " + format);
|
|
||||||
}
|
|
||||||
|
|
||||||
EscherBSERecord r = new EscherBSERecord();
|
|
||||||
r.setRecordId( EscherBSERecord.RECORD_ID );
|
|
||||||
r.setOptions( (short) ( 0x0002 | ( format << 4 ) ) );
|
|
||||||
r.setBlipTypeMacOS( (byte) format );
|
|
||||||
r.setBlipTypeWin32( (byte) format );
|
|
||||||
r.setUid( uid );
|
|
||||||
r.setTag( escherTag );
|
|
||||||
r.setSize( blipSize );
|
|
||||||
r.setRef( 0 );
|
|
||||||
r.setOffset( 0 );
|
|
||||||
r.setBlipRecord( blipRecord );
|
|
||||||
|
|
||||||
return workbook.addBSERecord( r );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all pictures from the Workbook.
|
* Gets all pictures from the Workbook.
|
||||||
*
|
*
|
||||||
|
@ -513,22 +513,6 @@ public interface Workbook extends Closeable, Iterable<Sheet> {
|
|||||||
*/
|
*/
|
||||||
DataFormat createDataFormat();
|
DataFormat createDataFormat();
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a picture to the workbook.
|
|
||||||
*
|
|
||||||
* @param pictureData The bytes of the picture
|
|
||||||
* @param format The format of the picture.
|
|
||||||
*
|
|
||||||
* @return the index to this picture (1 based).
|
|
||||||
* @see #PICTURE_TYPE_EMF
|
|
||||||
* @see #PICTURE_TYPE_WMF
|
|
||||||
* @see #PICTURE_TYPE_PICT
|
|
||||||
* @see #PICTURE_TYPE_JPEG
|
|
||||||
* @see #PICTURE_TYPE_PNG
|
|
||||||
* @see #PICTURE_TYPE_DIB
|
|
||||||
*/
|
|
||||||
int addPicture(byte[] pictureData, int format);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all pictures from the Workbook.
|
* Gets all pictures from the Workbook.
|
||||||
*
|
*
|
||||||
|
@ -26,15 +26,13 @@ import java.io.OutputStreamWriter;
|
|||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
import org.apache.commons.codec.CharEncoding;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dump data in hexadecimal format
|
* dump data in hexadecimal format
|
||||||
*/
|
*/
|
||||||
@Internal
|
@Internal
|
||||||
public class HexDump {
|
public class HexDump {
|
||||||
public static final String EOL = System.getProperty("line.separator");
|
public static final String EOL = System.getProperty("line.separator");
|
||||||
public static final Charset UTF8 = Charset.forName(CharEncoding.UTF_8);
|
public static final Charset UTF8 = Charset.forName("UTF-8");
|
||||||
|
|
||||||
private HexDump() {
|
private HexDump() {
|
||||||
// all static methods, so no need for a public constructor
|
// all static methods, so no need for a public constructor
|
||||||
|
Loading…
Reference in New Issue
Block a user