001/* 002 * Copyright 2002-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.jca.cci.core.support; 018 019import java.io.IOException; 020import java.io.InputStream; 021import java.io.OutputStream; 022import javax.resource.cci.Record; 023import javax.resource.cci.Streamable; 024 025import org.springframework.util.FileCopyUtils; 026 027/** 028 * CCI Record implementation for a COMMAREA, holding a byte array. 029 * 030 * @author Thierry Templier 031 * @author Juergen Hoeller 032 * @since 1.2 033 * @see org.springframework.jca.cci.object.MappingCommAreaOperation 034 */ 035@SuppressWarnings("serial") 036public class CommAreaRecord implements Record, Streamable { 037 038 private byte[] bytes; 039 040 private String recordName; 041 042 private String recordShortDescription; 043 044 045 /** 046 * Create a new CommAreaRecord. 047 * @see #read(java.io.InputStream) 048 */ 049 public CommAreaRecord() { 050 } 051 052 /** 053 * Create a new CommAreaRecord. 054 * @param bytes the bytes to fill the record with 055 */ 056 public CommAreaRecord(byte[] bytes) { 057 this.bytes = bytes; 058 } 059 060 061 @Override 062 public void setRecordName(String recordName) { 063 this.recordName = recordName; 064 } 065 066 @Override 067 public String getRecordName() { 068 return this.recordName; 069 } 070 071 @Override 072 public void setRecordShortDescription(String recordShortDescription) { 073 this.recordShortDescription = recordShortDescription; 074 } 075 076 @Override 077 public String getRecordShortDescription() { 078 return this.recordShortDescription; 079 } 080 081 082 @Override 083 public void read(InputStream in) throws IOException { 084 this.bytes = FileCopyUtils.copyToByteArray(in); 085 } 086 087 @Override 088 public void write(OutputStream out) throws IOException { 089 out.write(this.bytes); 090 out.flush(); 091 } 092 093 public byte[] toByteArray() { 094 return this.bytes; 095 } 096 097 098 @Override 099 public Object clone() { 100 return new CommAreaRecord(this.bytes); 101 } 102 103}