Java Collection Serialize serialize(List features)

Here you can find the source of serialize(List features)

Description

Serialize to byte array

License

Open Source License

Parameter

Parameter Description
features a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static byte[] serialize(List<double[]> features) throws IOException 

Method Source Code

//package com.java2s;
/**//from w w w. ja  v a 2  s  .c  o m
 * This file is part of Flipper Open Reverse Image Search.
    
 Flipper Open Reverse Image Search is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
    
 Flipper Open Reverse Image Search is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with Flipper Open Reverse Image Search.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.*;

import java.util.List;

public class Main {
    /**
     * Serialize to byte array
     * @param features
     * @return
     * @throws IOException
     */
    public static byte[] serialize(List<double[]> features) throws IOException {

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(bos);

        out.writeObject(features);
        byte[] result = bos.toByteArray();
        out.close();

        return result;
    }
}

Related

  1. serialize(Map> in, OutputStream out)
  2. serializeMap(Map map, File file)
  3. serializeSet(Set set)
  4. SerializeVectorOfInts(Vector m)