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

com.comcast.drivethru.transform.Transformer Maven / Gradle / Ivy

There is a newer version: 2.0.7
Show newest version
/**
 * Copyright 2013 Comcast Cable Communications Management, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.comcast.drivethru.transform;

import com.comcast.drivethru.exception.HttpException;


/**
 * A {@link Transformer} provides the underlying capability to transform between Java objects and
 * the byte array payload of an HTTP body.
 *
 * @author Clark Malmgren
 */
public interface Transformer {

    /**
     * The MIME type associated with the
     * HTTP body format that this {@link Transformer} supports
     *
     * @return the MIME type
     */
    String getMime();

    /**
     * Write the given java object to an array of bytes to be included in a HTTP body.
     *
     * @param t
     *            the java object to transform
     *
     * @return the transformed byte array
     *
     * @throws HttpException
     *             if a problem occurs while transforming
     */
     byte[] write(T t) throws HttpException;

    /**
     * Read the given body into a java object of the given type.
     *
     * @param body
     *            the body
     * @param type
     *            the java type of the object to create
     *
     * @return the transformed java object
     *
     * @throws HttpException
     *             if a problem occurs while transforming
     */
     T read(byte[] body, Class type) throws HttpException;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy