Java Fax – Retrieve the Image of a Received Fax

In this section, GetImageChunk is used to retrieve an image for an inbound (received) Java fax. To retrieve the fax image, you need to first use the GetList method to get the fax message ID.

The following Java fax API snippet retrieves a fax image in the form of multiple chunks (the chunk size can be configured).

The snippet below can also be found as part of the ZIP file above (see the green ‘Download’ box), under interfaxJavaSamples > src > GetFaxWithGetImageChunk.


import net.interfax.inbound.GetImageChunk;
import net.interfax.inbound.GetImageChunkResponse;
import net.interfax.outbound.TestConstants;

public class GetFaxWithGetImageChunk {

    /******** Begin settings ********/
    static String USERNAME = "";      // Enter your Interfax username here
    static String PASSWORD = "";      // Enter your Interfax password here
    static int MESSAGE_ID = 0;        // Transaction ID of the inbound message to be read
    static int MESSAGE_SIZE = 0;      // Size in bytes of the inbound message.
    static boolean MARK_AS_READ = false; // Mark the item as 'read' after downloading? If TRUE, 
                                      // item will no longer be 'new' and will be shown upon
                                      // subsequent list retrieval via GetList
    private static long CHUNK_SIZE = 100000l;
    /******** End settings ********/

    public static void main(String[] anArgs) {
        try {
            net.interfax.inbound.InboundSoapStub theBinding = (net.interfax.inbound.InboundSoapStub) new net.interfax.inbound.InboundLocator().getInboundSoap();

            ByteArrayOutputStream os = new ByteArrayOutputStream(MESSAGE_SIZE);
            long from = 0l;
            for( long i=0; i