1 package com.knowgate.misc; 2 3 import java.io.InputStream ; 4 import java.io.Serializable ; 5 import java.io.EOFException ; 6 7 import com.knowgate.debug.DebugFile; 8 9 31 32 37 public class ByteStore implements Serializable { 38 39 byte[] bytes; 40 41 String content_type=null; 42 String content_encoding=null; 43 String name; 44 String description=""; 45 46 public ByteStore(byte[] b, String sContentType) { 47 bytes=b; 48 content_type = sContentType; 49 } 50 51 public void setDescription(String s) { 52 description=s; 53 } 54 55 public String getDescription() { 56 return description; 57 } 58 59 public void setContentType(String s) { 60 content_type=s; 61 } 62 63 public String getContentType() { 64 return content_type; 65 73 } 74 75 public void setContentEncoding(String s) { 76 content_encoding=s; 77 } 78 79 public String getContentEncoding() { 80 return content_encoding; 81 } 82 83 public byte[] getBytes() { 84 return bytes; 85 } 86 87 public void setName(String s) { 88 name=s; 89 } 90 91 public String getName() { 92 return name; 93 } 94 95 public int getSize() { 96 return bytes.length; 97 } 98 99 100 103 public static ByteStore getBinaryFromIS(InputStream in, int nr_bytes_to_read, String sContentType) { 104 byte[] s=new byte[nr_bytes_to_read+100]; 105 int count=0; 106 int lastread=0; 107 if(in != null) { 108 synchronized(in) { 109 while(count < s.length) { 110 try { 111 lastread=in.read(s,count,nr_bytes_to_read-count); 112 } catch(EOFException ex) { 113 if (DebugFile.trace) DebugFile.writeln("EOFException " + ex.getMessage()); 114 lastread=0; 115 } catch(Exception z) { 116 if (DebugFile.trace) DebugFile.writeln(z.getClass().getName() + " " + z.getMessage()); 117 lastread=0; 118 } 119 count+=lastread; 120 if(lastread < 1) break; 121 } 122 } 123 byte[] s2=new byte[count+1]; 124 for(int i=0; i<count+1;i++) { 125 s2[i]=s[i]; 126 } 127 ByteStore d=new ByteStore(s2, sContentType); 128 return d; 129 } else { 130 return null; 131 } 132 } 133 } | Popular Tags |