Простой способ сделать это - сохранить фрагменты в структуре таблицы, затем прочитать их обратно и записать данные в файл в виде файла изображения.
Вот пример структуры таблицы.
public class Chunk
{
private int chunkId;
private byte[] chunkdata;
private int nextchunkId;
}
Метод чтения фрагмента из таблицы
private Chunk getChunk(int index){
Chunk chunk = null;
if(index == 1){ // this assumes that the chunk id starts from 1
//get and return Chunk where chunkId == 1 from the table
}
else{
// get and return Chunk where nextchunkId == index from the table
}
return chunk
}
Теперь запишите фрагменты в двоичный файл напрямую
private void mergeChunksToFile(){
int index = 1; // this assumes that the chunk id starts from 1
// Create a binary file in append mode to store the data, which is the image
Chunk chunk = getChunk(index);
while(chunk != null){
// Here, write chunk.chunkdata to the binary file
index = chunk.nextchunkId;
// get the next chunk
chunk = getChunk(index);
}
}
Возможно, это не лучшее решение, но это должно помочь вам иметь представление о том, как go об этом без использования какой-либо внешней библиотеки