Author: jim.ma
Date: 2010-04-09 03:14:25 -0400 (Fri, 09 Apr 2010)
New Revision: 11966
Modified:
stack/native/tags/jbossws-native-2.0.1.SP2_CP08/src/main/java/org/jboss/ws/core/utils/MimeUtils.java
Log:
[JBPAPP-4071]:removed Sun's JVM proprietary API
Modified:
stack/native/tags/jbossws-native-2.0.1.SP2_CP08/src/main/java/org/jboss/ws/core/utils/MimeUtils.java
===================================================================
---
stack/native/tags/jbossws-native-2.0.1.SP2_CP08/src/main/java/org/jboss/ws/core/utils/MimeUtils.java 2010-04-09
07:11:50 UTC (rev 11965)
+++
stack/native/tags/jbossws-native-2.0.1.SP2_CP08/src/main/java/org/jboss/ws/core/utils/MimeUtils.java 2010-04-09
07:14:25 UTC (rev 11966)
@@ -1,39 +1,40 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
package org.jboss.ws.core.utils;
-// $Id$
-
import java.awt.image.BufferedImage;
-import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import javax.imageio.ImageIO;
+import javax.imageio.ImageReader;
+import javax.imageio.ImageWriter;
+import javax.imageio.stream.ImageInputStream;
+import javax.imageio.stream.ImageOutputStream;
import javax.mail.internet.ContentType;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.ParseException;
@@ -45,10 +46,6 @@
import org.jboss.wsf.common.IOUtils;
import org.jboss.wsf.common.JavaUtils;
-import com.sun.image.codec.jpeg.JPEGCodec;
-import com.sun.image.codec.jpeg.JPEGImageDecoder;
-import com.sun.image.codec.jpeg.JPEGImageEncoder;
-
/**
* Generic mime utility class.
*
@@ -223,15 +220,18 @@
{
public Object readFrom(InputStream in) {
Object converted = null;
+
try
{
- JPEGImageDecoder dec = JPEGCodec.createJPEGDecoder(in);
- BufferedImage bim = dec.decodeAsBufferedImage();
+ ImageReader decoder =
ImageIO.getImageReadersByFormatName("JPEG").next();
+ ImageInputStream iis = ImageIO.createImageInputStream(in);
+ decoder.setInput(iis);
+ BufferedImage bim = decoder.read(0);
converted = bim;
}
catch (Exception e)
{
- // ignore
+ e.printStackTrace();
}
return converted;
@@ -240,10 +240,12 @@
public void writeTo(Object obj, OutputStream out) {
if(obj instanceof BufferedImage)
{
- JPEGImageEncoder enc = JPEGCodec.createJPEGEncoder(out);
+ ImageWriter encoder =
ImageIO.getImageWritersByFormatName("JPEG").next();
try
{
- enc.encode((BufferedImage)obj);
+ ImageOutputStream ios = ImageIO.createImageOutputStream(out);
+ encoder.setOutput(ios);
+ encoder.write((BufferedImage)obj);
}
catch (IOException e)
{
@@ -291,17 +293,12 @@
Object converted = null;
try
{
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- StringBuilder sb = new StringBuilder();
- String line = null;
-
- while ((line = br.readLine()) != null) {
- sb.append(line + "\n");
+ StringBuilder out = new StringBuilder();
+ byte[] b = new byte[4096];
+ for (int n; (n = in.read(b)) != -1;) {
+ out.append(new String(b, 0, n));
}
-
- br.close();
-
- converted = sb.toString();
+ converted = out.toString();
}
catch (IOException e)
{
@@ -398,7 +395,4 @@
{
Object readFrom(InputStream in);
void writeTo(Object obj, OutputStream out);
- }
-
-
-}
+ }
\ No newline at end of file