October 22, 2024
Chicago 12, Melborne City, USA
java

error: cannot find symbol for Mendix Java action


I am trying to use a Java action which splits up a file in Mendix, however I am getting the following error:

error: cannot find symbol
[compile] 2024-10-21T08:10:41.903741098Z [javac] block.setContents(getContext(), bis, length);
[compile] 2024-10-21T08:10:41.903743635Z [javac] ^
[compile] 2024-10-21T08:10:41.903746354Z [javac] symbol: method setContents(IContext,ByteArrayInputStream,long)
[compile] 2024-10-21T08:10:41.903749848Z [javac] location: variable block of type SplitBlock

I am not a Java developer so any help would be appreciated.

Java code:

package archival.actions;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import com.mendix.core.Core;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
import org.apache.commons.io.IOUtils;
import archival.proxies.SplitBlock;
import com.mendix.systemwideinterfaces.core.IMendixObject;

public class SplitFile extends CustomJavaAction<java.util.List<IMendixObject>>
{
    private IMendixObject __File;
    private system.proxies.FileDocument File;
    private java.lang.Long BlockSize;

    public SplitFile(IContext context, IMendixObject File, java.lang.Long BlockSize)
    {
        super(context);
        this.__File = File;
        this.BlockSize = BlockSize;
    }

    @java.lang.Override
    public java.util.List<IMendixObject> executeAction() throws Exception
    {
        this.File = this.__File == null ? null : system.proxies.FileDocument.initialize(getContext(), __File);

        // BEGIN USER CODE
        List<IMendixObject> result = new ArrayList<IMendixObject>();

        if (this.File == null) {
            throw new IllegalArgumentException("Source file is null");
        }
        if (!this.File.getHasContents()) {
            throw new IllegalArgumentException("Source file has no contents!");
        }
        
        try (InputStream attachment = Core.getFileDocumentContent(getContext(), File.getMendixObject())) {

            byte[] bytes = IOUtils.toByteArray(attachment);
            ByteArrayInputStream bis = new ByteArrayInputStream(bytes);

            long offset = 0;
            long fileSize = bytes.length;
            long length = this.BlockSize.longValue();

            while (offset < fileSize && length > 0) {
                length = offset+this.BlockSize < fileSize ? this.BlockSize.intValue() : fileSize-offset;
            
                SplitBlock block = new SplitBlock(getContext());
                block.setOffset(getContext(), offset);
                block.setLength(getContext(), length);
                block.setContents(getContext(), bis, length);

                result.add(block.getMendixObject());

                offset += length;           
            } 
        } 
        return result;
        // END USER CODE
    }

    /**
     * Returns a string representation of this action
     * @return a string representation of this action
     */
    @java.lang.Override
    public java.lang.String toString()
    {
        return "SplitFile";
    }

    // BEGIN EXTRA CODE
    // END EXTRA CODE
}

Thanks in advance



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video