import org.squeryl.dsl._
import org.squeryl.PrimitiveTypeMode._
import java.io.FileInputStream
+import java.io.FileOutputStream
+import java.io.BufferedInputStream
+import java.io.BufferedOutputStream
case class AtachManager(){
def uploadAtach(atach:FilePart[TemporaryFile], grpName:String, partId:Long, notifyId:Long, replyId:Long) = {
val filename = atach.filename
val contentType = atach.contentType
- var folder = Messages("atach.folder")
+ val file = atach.ref.file
+ val fis = new FileInputStream(file)
+ val bis = new BufferedInputStream(fis)
+ val byteBuffer = new Array[Byte](file.length().toInt)
+ bis.read(byteBuffer)
+ bis.close()
+ fis.close()
+ //実ファイルで実装するなら以下5行で実装
+/* var folder = Messages("atach.folder")
if(!folder.endsWith("/")) {folder = folder.concat("/")}
- val url = folder + filename
+ val url = folder + filename
+ val file = new File(url)
atach.ref.moveTo(new File(url), true)
- val newAtach = Atach(contentType.get, filename, grpName, partId, notifyId, replyId)
+*/
+ val newAtach = Atach(byteBuffer, contentType.get, filename, grpName, partId, notifyId, replyId)
if(partId != 0) {
associateAtach(PartManager(), partId, newAtach)
}
def showAtach(id: Long):Array[Byte] = {
val atach = getById(id)
- val file = new File(Messages("atach.folder") + "/" + atach.fileName)
+ return atach.lob
+ // 実ファイルで実装するなら以下5行
+/* val file = new File(Messages("atach.folder") + "/" + atach.fileName)
val data = new Array[Byte](file.length().asInstanceOf[Int])
val io = new FileInputStream(file)
io.read(data)
io.close
- return data
+ return data*/
}
def getById(id: Long):Atach = {