/*    */ package com.picc.grab.util;
/*    */ 
/*    */ import com.picc.grab.common.OSSMethod;
/*    */ import com.picc.grab.config.UploadConfig;
/*    */ import com.picc.grab.domain.Carimg;
/*    */ import java.io.ByteArrayInputStream;
/*    */ import java.io.ByteArrayOutputStream;
/*    */ import java.io.IOException;
/*    */ import java.io.InputStream;
/*    */ import java.net.URL;
/*    */ import java.util.UUID;
/*    */ import org.apache.commons.io.IOUtils;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.stereotype.Component;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ @Component
/*    */ public class ImageDownLocad
/*    */ {
/*    */   @Autowired
/*    */   private UploadConfig uploadConfig;
/*    */   
/*    */   public Carimg findImg(String src) {
/* 27 */     Carimg carimg = new Carimg();
/*    */     
/* 29 */     String imgPath = "";
/* 30 */     String simgPath = "";
/*    */     try {
/* 32 */       byte[] fileBytes = IOUtils.toByteArray(new URL(src));
/*    */       
/* 34 */       imgPath = this.uploadConfig.logoImgPath + UUID.randomUUID().toString().replaceAll("-", "") + ".jpg";
/* 35 */       simgPath = this.uploadConfig.logoImgPath + UUID.randomUUID().toString().replaceAll("-", "") + "slt.jpg";
/* 36 */       ByteArrayOutputStream bitstream = cloneInputStream(new ByteArrayInputStream(fileBytes));
/* 37 */       if (bitstream != null) {
/*    */         
/* 39 */         InputStream imgStream = new ByteArrayInputStream(bitstream.toByteArray());
/*    */         
/* 41 */         carimg.setUrl(this.uploadConfig.readUrl + imgPath);
/*    */         
/* 43 */         InputStream sltIs = ThumbnailatorUtil.imgToMin(new ByteArrayInputStream(bitstream.toByteArray()), 400, ".jpg");
/*    */         
/* 45 */         OSSMethod.putObject(this.uploadConfig.getSingletonInstance(), this.uploadConfig.bucketName, imgPath, imgStream);
/* 46 */         OSSMethod.putObject(this.uploadConfig.getSingletonInstance(), this.uploadConfig.bucketName, simgPath, sltIs);
/*    */         
/* 48 */         carimg.setSurl(this.uploadConfig.readUrl + simgPath);
/* 49 */         carimg.setType(Integer.valueOf(1));
/* 50 */         return carimg;
/*    */       } 
/* 52 */     } catch (Exception e) {
/* 53 */       e.printStackTrace();
/*    */     } 
/* 55 */     return null;
/*    */   }
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   private ByteArrayOutputStream cloneInputStream(InputStream input) {
/*    */     try {
/* 63 */       ByteArrayOutputStream baos = new ByteArrayOutputStream();
/* 64 */       byte[] buffer = new byte[1024];
/*    */       int len;
/* 66 */       while ((len = input.read(buffer)) > -1) {
/* 67 */         baos.write(buffer, 0, len);
/*    */       }
/* 69 */       baos.flush();
/* 70 */       return baos;
/* 71 */     } catch (IOException e) {
/* 72 */       e.printStackTrace();
/* 73 */       return null;
/*    */     } 
/*    */   }
/*    */ }


/* Location:              C:\Users\Administrator\Desktop\ROOT\WEB-INF\classes\!\com\picc\gra\\util\ImageDownLocad.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */