# CustomJavaWriter - How to write file from byte

**URL:** <https://forum.cloverdx.com/t/customjavawriter-how-to-write-file-from-byte/2092>\
**Category:** CloverDX Platform\
**Created:** [July 20, 2020, 12:00am UTC](https://forum.cloverdx.com/t/customjavawriter-how-to-write-file-from-byte/2092 "2020-07-20T00:00:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomapi](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@tomapi](https://forum.cloverdx.com/u/tomapi)\
**Post date:** [July 20, 2020, 12:00am UTC](https://forum.cloverdx.com/t/customjavawriter-how-to-write-file-from-byte/2092/1 "2020-07-20T00:00:00Z")

</div>

Hello,

I’ve tried to use UniversalDataWriter without success and have now switched to CustomJavaWriter. I would like to write a file as image from a database BLOB.

I’ve a loop to process each record and then this code:  
Object objLogo = record.getField(“logo”).getValue();  
String fileUrl = “…”;  
try (OutputStream os = getOutputStream(fileUrl, false)) {  
os.write(objLogo);  
}  
catch (IOException e) {  
throw new JetelRuntimeException(e);  
}  
I don’t know if the Clover byte is directly mapped to a Java byte / byte array. I’ve checked the javadoc without success.

What is the best java object to map the defined Clover byte to? Could you help me?

Thanks,

Thomas

---

<div class="post-metadata">

**Author:** ![tomapi](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@tomapi](https://forum.cloverdx.com/u/tomapi)\
**Post date:** [July 21, 2020, 4:42pm UTC](https://forum.cloverdx.com/t/customjavawriter-how-to-write-file-from-byte/2092/2 "2020-07-21T16:42:08Z")

</div>

Found the solution - it’s simple - byte field type has to be mapped to byte array as:  
Object objLogo = record.getField(“logo”).getValue();  
byte logo = (byte) objLogo;  
try (OutputStream os = getOutputStream(fileUrl, false)) {  
os.write(logo);  
}  
catch (IOException e) {  
throw new JetelRuntimeException(e);  
}

---

<div class="post-metadata">

**Author:** ![David\_Hlidek](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@David\_Hlidek](https://forum.cloverdx.com/u/David_Hlidek)\
**Post date:** [July 29, 2020, 8:35am UTC](https://forum.cloverdx.com/t/customjavawriter-how-to-write-file-from-byte/2092/3 "2020-07-29T08:35:39Z")

</div>

Hi Thomas,

I am glad to see that you have successfully achieved your goal using the CustomJavaComponent. Thanks for posting the solution.

However, I am a little bit concerned about the UniversalDataWriter difficulties as well. Would you be so kind and tell me what exactly have you experienced? As a matter of fact, the UniversalDataWriter should be able to write the byte field type to file as well. I have created a simple graph for your review (in attachment, use any picture as input data). Please review especially the metadata setup:

[metadataByte.jpg](https://cdn.cloverdx.com/forum/18302%5F4add3b2c287d3160a76ff6b2c9164611/metadataByte.jpg)

Please let me know what is your use case and what issue exactly you have encountered as I can provide more details. Thank you, Eva

- [byteTest.grf](https://cdn.cloverdx.com/forum/18302%5F34480e76d9ba3c57deaac1aa3b34b787/byteTest.grf)
- [metadataByte.jpg](https://cdn.cloverdx.com/forum/18302%5F4add3b2c287d3160a76ff6b2c9164611/metadataByte.jpg)
