All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.razorvine.pickle.objects.ByteArrayConstructor Maven / Gradle / Ivy

package net.razorvine.pickle.objects;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

import net.razorvine.pickle.IObjectConstructor;
import net.razorvine.pickle.PickleException;

/**
 * Creates byte arrays (byte[]).
 * 
 * @author Irmen de Jong ([email protected])
 */
public class ByteArrayConstructor implements IObjectConstructor {

	public Object construct(Object[] args) throws PickleException {
		// args for bytearray constructor: [ String string, String encoding ]
		// args for bytearray constructor (from python3 bytes): [ ArrayList ]
		if (args.length != 1 && args.length != 2)
			throw new PickleException("invalid pickle data for bytearray; expected 1 or 2 args, got "+args.length);

		if(args.length==1) {
			@SuppressWarnings("unchecked")
			ArrayListvalues=(ArrayList)args[0];
			byte[] data=new byte[values.size()];
			for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy