Example usage for java.util.zip DataFormatException DataFormatException

List of usage examples for java.util.zip DataFormatException DataFormatException

Introduction

In this page you can find the example usage for java.util.zip DataFormatException DataFormatException.

Prototype

public DataFormatException(String s) 

Source Link

Document

Constructs a DataFormatException with the specified detail message.

Usage

From source file:Main.java

public static InputStream inflate(byte[] deflatedToken, boolean nowrap) throws DataFormatException {
    Inflater inflater = new Inflater(nowrap);
    inflater.setInput(deflatedToken);/*from  w w  w  .  j  av a 2s .  c  o m*/

    byte[] input = new byte[deflatedToken.length * 2];
    int inflatedLen = 0;
    int inputLen = 0;
    byte[] inflatedToken = input;
    while (!inflater.finished()) {
        inputLen = inflater.inflate(input);
        if (!inflater.finished()) {

            if (inputLen == 0) {
                if (inflater.needsInput()) {
                    throw new DataFormatException("Inflater can not inflate all the token bytes");
                } else {
                    break;
                }
            }

            inflatedToken = new byte[input.length + inflatedLen];
            System.arraycopy(input, 0, inflatedToken, inflatedLen, inputLen);
            inflatedLen += inputLen;
        }
    }
    InputStream is = new ByteArrayInputStream(input, 0, inputLen);
    if (inflatedToken != input) {
        is = new SequenceInputStream(new ByteArrayInputStream(inflatedToken, 0, inflatedLen), is);
    }
    return is;
}

From source file:v7db.files.Compression.java

/**
 * assumes that the result buffer has exactly the needed size
 * //from   w w  w  .  j  ava  2 s.  co m
 * @throws DataFormatException
 */
static void inflate(byte[] data, int off, int len, byte[] out) throws DataFormatException {
    Inflater inflater = new Inflater(true);
    inflater.setInput(data, off, len);
    int size = inflater.inflate(out);
    if (size != out.length)
        throw new DataFormatException(
                "unexpected size of deflated data: " + size + " instead of " + out.length);
}

From source file:gov.nasa.ensemble.common.ERGBUtils.java

/**
 * COPIED FROM org.eclipse.jface.resource.StringConverter
 * /*from  w w  w .  j  a va  2  s . c o m*/
 * Converts the given value into an SWT RGB color value.
 * This method fails if the value does not represent an RGB
 * color value.
 * <p>
 * A valid RGB color value representation is a string of the form
 * <code><it>red</it>,<it>green</it></code>,<it>blue</it></code> where
 * <code><it>red</it></code>, <it>green</it></code>, and 
 * <code><it>blue</it></code> are valid ints.
 * </p>
 *
 * @param value the value to be converted
 * @return the value as an RGB color value
 * @exception DataFormatException if the given value does not represent
 *   an RGB color value
 */
private static ERGB asRGB(String value) throws DataFormatException {
    if (value == null) {
        throw new DataFormatException("Null doesn't represent a valid RGB"); //$NON-NLS-1$
    }
    StringTokenizer stok = new StringTokenizer(value, ","); //$NON-NLS-1$

    try {
        String red = stok.nextToken().trim();
        String green = stok.nextToken().trim();
        String blue = stok.nextToken().trim();
        int rval = 0, gval = 0, bval = 0;
        try {
            rval = Integer.parseInt(red);
            gval = Integer.parseInt(green);
            bval = Integer.parseInt(blue);
        } catch (NumberFormatException e) {
            throw new DataFormatException(e.getMessage());
        }
        return new ERGB(rval, gval, bval);
    } catch (NoSuchElementException e) {
        throw new DataFormatException(e.getMessage());
    }
}

From source file:bachelorthesis.methods.detection.bayesian.BayesianDetection.java

private double[] add(double[] array1, double[] array2) {
    if (array1.length != array2.length) {
        ExceptionHandler.handleOwnException(new DataFormatException("Arrays are of different length"));
    }//from  w  ww  . ja v a2s .c  o m
    double[] result = new double[array1.length];
    for (int i = 0; i < array1.length; i++) {
        result[i] = array1[i] + array2[i];
    }
    return result;
}

From source file:org.openml.apiconnector.io.OpenmlConnector.java

/**
 * Retrieves the description of a specified data set.
 * //from w  w  w  .  j a va  2 s.c o m
 * @param did
 *            - The data_id of the data description to download.
 * @return DataSetDescription - An object containing the description of the
 *         data
 * @throws Exception
 *             - Can be: API Error (see documentation at openml.org), server
 *             down, etc.
 */
public DataSetDescription dataGet(int did) throws Exception {
    if (Caching.in_cache("datadescription", did, "xml") || Settings.LOCAL_OPERATIONS) {
        String dsdString = Conversion.fileToString(Caching.cached("datadescription", did, "xml"));
        return (DataSetDescription) HttpConnector.xstreamClient.fromXML(dsdString);
    }

    Object apiResult = HttpConnector.doApiRequest(OPENML_URL + API_PART + "data/" + did, getApiKey(),
            verboseLevel);
    if (apiResult instanceof DataSetDescription) {
        if (Settings.CACHE_ALLOWED) {
            try {
                Caching.cache(apiResult, "datadescription", did, "xml");
            } catch (IOException e) {
                Conversion.log("Warning", "DataGet", "Cache Store Exception: " + e.getMessage());
            }
        }
        return (DataSetDescription) apiResult;
    } else {
        throw new DataFormatException("Casting Api Object to DataSetDescription");
    }
}

From source file:com.kactech.otj.Utils.java

public static byte[] zlibDecompress(byte[] data) throws IOException, DataFormatException {
    Inflater inflater = new Inflater(false);

    inflater.setInput(data);/*w  w  w.  j a  v a 2 s.  c o  m*/

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
    byte[] buffer = new byte[1024];
    while (!inflater.finished()) {
        int count = inflater.inflate(buffer);
        if (count == 0)
            throw new DataFormatException("probably bad, has infinite loop at encoded message");
        outputStream.write(buffer, 0, count);
    }
    outputStream.close();
    byte[] output = outputStream.toByteArray();

    return output;
}

From source file:org.openml.apiconnector.io.OpenmlConnector.java

/**
 * Uploads a new dataset/*from www  .ja v a 2s  .c om*/
 * 
 * @param description - xml file describing the dataset, according to XSD
 * @param dataset - arff file representing the dataset. optional. 
 * @return The id under which the dataset was uploaded
 * @throws Exception
 */
public UploadDataSet dataUpload(File description, File dataset) throws Exception {
    MultipartEntity params = new MultipartEntity();
    params.addPart("description", new FileBody(description));
    if (dataset != null) {
        params.addPart("dataset", new FileBody(dataset));
    }

    Object apiResult = HttpConnector.doApiRequest(OPENML_URL + API_PART + "data/", params, getApiKey(),
            verboseLevel);
    if (apiResult instanceof UploadDataSet) {
        return (UploadDataSet) apiResult;
    } else {
        throw new DataFormatException("Casting Api Object to UploadDataSet");
    }
}

From source file:org.openml.apiconnector.io.OpenmlConnector.java

/**
 * Deletes a dataset from the server/*from  w  ww  . jav  a 2  s .  c  o  m*/
 * 
 * @param did - The data id to be deleted
 * @return The id of the dataset that was deleted
 * @throws Exception
 */
public DataDelete dataDelete(int did) throws Exception {
    Object apiResult = HttpConnector.doApiDelete(OPENML_URL + API_PART + "data/" + did, getApiKey(),
            verboseLevel);
    if (apiResult instanceof DataDelete) {
        return (DataDelete) apiResult;
    } else {
        throw new DataFormatException("Casting Api Object to DataDelete");
    }
}

From source file:org.openml.apiconnector.io.OpenmlConnector.java

/**
 * Tags a dataset// w w w  . j  a v a2s . c om
 * 
 * @param id - the dataset to be tagged
 * @param tag - the tag to be used
 * @return
 * @throws Exception
 */
public DataTag dataTag(int id, String tag) throws Exception {
    MultipartEntity params = new MultipartEntity();
    params.addPart("data_id", new StringBody("" + id));
    params.addPart("tag", new StringBody(tag));

    Object apiResult = HttpConnector.doApiRequest(OPENML_URL + API_PART + "data/tag", params, getApiKey(),
            verboseLevel);
    if (apiResult instanceof DataTag) {
        return (DataTag) apiResult;
    } else {
        throw new DataFormatException("Casting Api Object to DataTag");
    }
}

From source file:org.openml.apiconnector.io.OpenmlConnector.java

/**
 * Untags a dataset//from   w  w w  .j  a  va 2 s . co  m
 * 
 * @param id - the id of the dataset
 * @param tag - the tag to be remoeved
 * @return
 * @throws Exception
 */
public DataUntag dataUntag(int id, String tag) throws Exception {
    MultipartEntity params = new MultipartEntity();
    params.addPart("data_id", new StringBody("" + id));
    params.addPart("tag", new StringBody(tag));

    Object apiResult = HttpConnector.doApiRequest(OPENML_URL + API_PART + "data/untag", params, getApiKey(),
            verboseLevel);
    if (apiResult instanceof DataUntag) {
        return (DataUntag) apiResult;
    } else {
        throw new DataFormatException("Casting Api Object to DataUntag");
    }
}