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; 022 023import javax.resource.cci.Record; 024import javax.resource.cci.Streamable; 025 026import org.springframework.util.FileCopyUtils; 027 028/** 029 * CCI Record implementation for a COMMAREA, holding a byte array. 030 * 031 * @author Thierry Templier 032 * @author Juergen Hoeller 033 * @since 1.2 034 * @see org.springframework.jca.cci.object.MappingCommAreaOperation 035 */ 036@SuppressWarnings("serial") 037public class CommAreaRecord implements Record, Streamable { 038 039 private byte[] bytes = new byte[0]; 040 041 private String recordName = ""; 042 043 private String recordShortDescription = ""; 044 045 046 /** 047 * Create a new CommAreaRecord. 048 * @see #read(java.io.InputStream) 049 */ 050 public CommAreaRecord() { 051 } 052 053 /** 054 * Create a new CommAreaRecord. 055 * @param bytes the bytes to fill the record with 056 */ 057 public CommAreaRecord(byte[] bytes) { 058 this.bytes = bytes; 059 } 060 061 062 @Override 063 public void setRecordName(String recordName) { 064 this.recordName = recordName; 065 } 066 067 @Override 068 public String getRecordName() { 069 return this.recordName; 070 } 071 072 @Override 073 public void setRecordShortDescription(String recordShortDescription) { 074 this.recordShortDescription = recordShortDescription; 075 } 076 077 @Override 078 public String getRecordShortDescription() { 079 return this.recordShortDescription; 080 } 081 082 083 @Override 084 public void read(InputStream in) throws IOException { 085 this.bytes = FileCopyUtils.copyToByteArray(in); 086 } 087 088 @Override 089 public void write(OutputStream out) throws IOException { 090 out.write(this.bytes); 091 out.flush(); 092 } 093 094 public byte[] toByteArray() { 095 return this.bytes; 096 } 097 098 099 @Override 100 public Object clone() { 101 return new CommAreaRecord(this.bytes); 102 } 103 104}