Here you can find the source of blob2FloatArray(Blob blob)
Parameter | Description |
---|---|
blob | from the database |
Parameter | Description |
---|---|
SQLException | an exception |
public static float[] blob2FloatArray(Blob blob)
//package com.java2s; /*/*ww w . j a v a 2 s .c o m*/ * Copyright (C) 2012 Joseph Areeda <joseph.areeda at ligo.org> * * This program 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. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.DataInputStream; import java.sql.Blob; public class Main { /** * Convert a blob that we wrote a float array back into a usable array * @param blob from the database * @return * @throws SQLException */ public static float[] blob2FloatArray(Blob blob) { float[] ret = null; try { int blen = (int) blob.length(); int nbytes = Float.SIZE / 8; int olen = (int) (blen / nbytes); ret = new float[olen]; DataInputStream dis = new DataInputStream(blob.getBinaryStream()); for (int o = 0; o < olen; o++) { ret[o] = dis.readFloat(); } } catch (Exception ex) { ret = null; } return ret; } }