Path: blob/master/test/jdk/javax/sql/testng/util/StubBlob.java
41153 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package util;2324import java.io.ByteArrayOutputStream;25import java.io.IOException;26import java.io.InputStream;27import java.io.ObjectOutputStream;28import java.io.OutputStream;29import java.sql.Blob;30import java.sql.SQLException;31import java.util.Arrays;32import java.util.logging.Level;33import java.util.logging.Logger;3435public class StubBlob implements Blob {3637private byte[] bytes;3839public StubBlob() {40bytes = new byte[]{2, 4, 6, 8};41}4243public long length() throws SQLException {44return bytes.length;45}4647public byte[] getBytes(long pos, int length)48throws SQLException {49return Arrays.copyOfRange(bytes, (int) pos - 1, length);50}5152public InputStream getBinaryStream()53throws SQLException {54return null;55}5657public long position(byte[] pattern, long start)58throws SQLException {59return 0;60}6162public long position(Blob pattern, long start)63throws SQLException {64return 0;65}6667public int setBytes(long pos, byte[] bytes)68throws SQLException {69return 0;70}7172public int setBytes(long pos, byte[] bytes, int offset, int len)73throws SQLException {74return 0;75}7677public OutputStream setBinaryStream(long pos)78throws SQLException {79ByteArrayOutputStream baos = new ByteArrayOutputStream();80ObjectOutputStream oos = null;81try {82oos = new ObjectOutputStream(baos);83} catch (IOException ex) {84Logger.getLogger(StubBlob.class.getName()).log(Level.SEVERE, null, ex);85}86return oos;87}8889public void truncate(long len)90throws SQLException {91}9293public void free() throws SQLException {94}9596public InputStream getBinaryStream(long pos, long length) throws SQLException {97return null;98}99}100101102