일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
- test
- Realm
- 웹기획자
- 앱기능설명
- 안드로이드
- 기획자역량
- 초등독서기록앱
- kotlin
- log
- convert
- 글라이드로앱만들기
- 초등독서기록앱만들기
- 해외여행데이터
- glide로앱만들기
- 기획자
- 앱기획자
- Gradle
- Glide
- 다윈
- 스트리밍
- Exception
- ethereum
- Android
- error
- eSIM
- 초등독서앱
- 컴파일
- C
- firebase
- 노코드활용
- Today
- Total
날마다 새롭게 또 날마다 새롭게
object를 byte로 변환 후, 전송하는 코드 본문
Step :
1. sendpack Object를 byteArrayO로 변환
2. byteArray를 파일로 저장
3. 파일을 다시 읽어온 후, outputstream으로 전송
PicPacket sendpack = new PicPacket();
sendpack.setPacket(null, file_stream.length, file_stream, filename, seq);
try
{
// object -> byte[]
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(sendpack);
byte[] objectBytes = bos.toByteArray();
byteToFile(objectBytes, PATH);
// 파일로 저장된 객체를 전송
InputStream inputStream = new FileInputStream(PATH);
OutputStream os = sock.getOutputStream();
byte[] buf = new byte[BUFFER_SIZE];
int total = 0;
int count;
while((count = inputStream.read(buf)) > 0) {
total += count;
os.write(buf, 0, count);
}
os.flush();
inputStream.close();
os.close();
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
finally
{
sock.close();
}