IDUnivocoGroupByPolicyStreamSerializer.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.pdd.core.controllo_traffico.policy.driver.hazelcast;

  21. import java.io.IOException;
  22. import java.io.InputStream;

  23. import org.openspcoop2.core.controllo_traffico.beans.IDUnivocoGroupByPolicy;
  24. import org.openspcoop2.utils.Utilities;
  25. import org.openspcoop2.utils.resources.Charset;

  26. import com.hazelcast.nio.ObjectDataInput;
  27. import com.hazelcast.nio.ObjectDataOutput;
  28. import com.hazelcast.nio.serialization.StreamSerializer;

  29. /**
  30.  * IDUnivocoGroupByPolicyStreamSerializer
  31.  *
  32.  * @author Andrea Poli (poli@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  */
  36. public class IDUnivocoGroupByPolicyStreamSerializer  implements StreamSerializer<IDUnivocoGroupByPolicy> {

  37.     @Override
  38.     public int getTypeId() {
  39.         return 1;
  40.     }

  41.     @Override
  42.     public IDUnivocoGroupByPolicy read(ObjectDataInput inParam) throws IOException {
  43.         InputStream inputStream = (InputStream) inParam;
  44.         try {
  45.             String s = Utilities.getAsString(inputStream, Charset.UTF_8.getValue());
  46.             return IDUnivocoGroupByPolicy.deserialize(s);
  47.         }catch(Exception e) {
  48.             throw new IOException(e.getMessage(),e);
  49.         }
  50.        
  51.     }

  52.     @Override
  53.     public void write(ObjectDataOutput out, IDUnivocoGroupByPolicy id) throws IOException {
  54.         out.write(IDUnivocoGroupByPolicy.serialize(id).getBytes(Charset.UTF_8.getValue()));
  55.     }

  56. }