- Timestamp:
- Sep 1, 2010, 6:48:53 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/transverse/util/Outil.java
r6821 r6831 2 2 3 3 import java.io.BufferedInputStream; 4 import java.io.ByteArrayInputStream; 5 import java.io.ByteArrayOutputStream; 4 6 import java.io.DataInputStream; 5 7 import java.io.File; 6 8 import java.io.FileInputStream; 9 import java.io.FileOutputStream; 7 10 import java.io.IOException; 8 11 import java.io.InputStream; … … 14 17 import java.net.URLClassLoader; 15 18 import java.security.MessageDigest; 16 19 import java.util.ArrayList; 20 21 import org.apache.sanselan.Sanselan; 22 import org.apache.sanselan.common.IImageMetadata; 23 import org.apache.sanselan.formats.jpeg.JpegImageMetadata; 24 import org.apache.sanselan.formats.jpeg.JpegPhotoshopMetadata; 25 import org.apache.sanselan.formats.jpeg.exifRewrite.ExifRewriter; 26 import org.apache.sanselan.formats.jpeg.iptc.JpegIptcRewriter; 27 import org.apache.sanselan.formats.jpeg.iptc.PhotoshopApp13Data; 28 import org.apache.sanselan.formats.tiff.write.TiffOutputSet; 17 29 import org.jdom.Document; 18 30 import org.jdom.JDOMException; … … 209 221 return result.toString(); 210 222 } 223 224 /** 225 * Function that splits a file 226 * @param fichier the file to split 227 * @param size the size of the resulting chunks 228 * @return the list of files 229 * @throws IOException 230 */ 231 //feature:0001827 232 public static ArrayList<File> splitFile(File fichier, int size) throws IOException { 233 FileInputStream fis = new FileInputStream(fichier); 234 byte buffer[] = new byte[size]; 235 ArrayList<File> listFichiers = new ArrayList<File>(); 236 int count = 0; 237 while (true) { 238 int i = fis.read(buffer, 0, size); 239 if (i == -1) 240 break; 241 File file = new File(System.getProperty("java.io.tmpdir") + "/tempcut" + count); 242 listFichiers.add(file); 243 FileOutputStream fos = new FileOutputStream(file); 244 fos.write(buffer, 0, i); 245 fos.flush(); 246 fos.close(); 247 248 ++count; 249 } 250 return listFichiers; 251 } 252 253 /** 254 * Function used to put the exif and iptc metadata from one image to another 255 * @param enriched original image where the metadata comes from 256 * @param naked image where to put metadata 257 * @return enriched image 258 * @throws Exception 259 */ 260 public static byte[] enrich(byte[] enriched, byte[] naked) throws Exception { 261 262 // read IPTC metadata from the original enriched image 263 IImageMetadata metadata = Sanselan.getMetadata(enriched); 264 JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; 265 JpegPhotoshopMetadata photoshopMetadata = jpegMetadata.getPhotoshop(); 266 if (photoshopMetadata == null) { 267 return naked; 268 } 269 270 PhotoshopApp13Data data = photoshopMetadata.photoshopApp13Data; 271 272 // read the EXIF metadata from the parsed JPEG metadata 273 TiffOutputSet outputSet = jpegMetadata.getExif().getOutputSet(); 274 275 // enrich the naked byte[] with EXIF metadata 276 ExifRewriter writer = new ExifRewriter(); 277 ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 278 writer.updateExifMetadataLossless(naked, outputStream, outputSet); 279 280 // enrich the partially clothed byte[] with IPTC metadata 281 InputStream src = new ByteArrayInputStream(outputStream.toByteArray()); 282 ByteArrayOutputStream dest = new ByteArrayOutputStream(); 283 new JpegIptcRewriter().writeIPTC(src, dest, data); 284 285 // return the fully clothed image as a byte[] 286 return dest.toByteArray(); 287 } 288 289 public static void byteToFile(String fichier, byte[] bytes) throws IOException { 290 FileOutputStream fos = new FileOutputStream(fichier); 291 fos.write(bytes); 292 fos.flush(); 293 fos.close(); 294 295 } 211 296 }
Note: See TracChangeset
for help on using the changeset viewer.