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 and file size.

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 java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

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. This value
                                      // is returned by method GetList, which should be run
                                      // before this one
    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();
            theBinding.setTimeout(60000);

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

Contact us today

Talk to a member of our team about the benefits InterFAX can bring to your organization's communications processes.

Contact us today