ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/jdbc/JdbcClob.java

Path
ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/jdbc/JdbcClob.java
Status
scanned
Type
file
Name
JdbcClob.java
Extension
.java
Programming language
Java
Mime type
text/x-java
File type
Java source, ASCII text
Tag

      
    
Rootfs path

      
    
Size
8368 (8.2 KB)
MD5
f20da6e5e8919f0eae55bd883a94766d
SHA1
fe827ed6b04e22e1c9d8aa68aab4e5b3a84dabb0
SHA256
128eb69ff557f48a578cf185afd9a5da60ea5047ccaa3099a66ba5d646388aa6
SHA512

      
    
SHA1_git
d2fb4f896d9480c8d8c9894ac394f8652f3dd05f
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
JdbcClob.java | 8.2 KB |

/* * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (https://h2database.com/html/license.html). * Initial Developer: H2 Group */ package org.h2.jdbc; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; import java.sql.Clob; import java.sql.NClob; import java.sql.SQLException; import org.h2.engine.Constants; import org.h2.message.DbException; import org.h2.message.TraceObject; import org.h2.store.RangeReader; import org.h2.util.IOUtils; import org.h2.value.Value; /** * Represents a CLOB value. */ public final class JdbcClob extends JdbcLob implements NClob { /** * INTERNAL * @param conn it belongs to * @param value of * @param state of the LOB * @param id of the trace object */ public JdbcClob(JdbcConnection conn, Value value, State state, int id) { super(conn, value, state, TraceObject.CLOB, id); } /** * Returns the length. * * @return the length */ @Override public long length() throws SQLException { try { debugCodeCall("length"); checkReadable(); if (value.getValueType() == Value.CLOB) { long precision = value.getType().getPrecision(); if (precision > 0) { return precision; } } return IOUtils.copyAndCloseInput(value.getReader(), null, Long.MAX_VALUE); } catch (Exception e) { throw logAndConvert(e); } } /** * [Not supported] Truncates the object. */ @Override public void truncate(long len) throws SQLException { throw unsupported("LOB update"); } /** * Returns the input stream. * * @return the input stream */ @Override public InputStream getAsciiStream() throws SQLException { try { debugCodeCall("getAsciiStream"); checkReadable(); String s = value.getString(); return IOUtils.getInputStreamFromString(s); } catch (Exception e) { throw logAndConvert(e); } } /** * [Not supported] Returns an output stream. */ @Override public OutputStream setAsciiStream(long pos) throws SQLException { throw unsupported("LOB update"); } @Override public Reader getCharacterStream() throws SQLException { return super.getCharacterStream(); } /** * Get a writer to update the Clob. This is only supported for new, empty * Clob objects that were created with Connection.createClob() or * createNClob(). The Clob is created in a separate thread, and the object * is only updated when Writer.close() is called. The position must be 1, * meaning the whole Clob data is set. * * @param pos where to start writing (the first character is at position 1) * @return a writer */ @Override public Writer setCharacterStream(long pos) throws SQLException { try { if (isDebugEnabled()) { debugCodeCall("setCharacterStream", pos); } checkEditable(); if (pos != 1) { throw DbException.getInvalidValueException("pos", pos); } state = State.SET_CALLED; return setCharacterStreamImpl(); } catch (Exception e) { throw logAndConvert(e); } } /** * Returns a substring. * * @param pos the position (the first character is at position 1) * @param length the number of characters * @return the string */ @Override public String getSubString(long pos, int length) throws SQLException { try { if (isDebugEnabled()) { debugCode("getSubString(" + pos + ", " + length + ')'); } checkReadable(); if (pos < 1) { throw DbException.getInvalidValueException("pos", pos); } if (length < 0) { throw DbException.getInvalidValueException("length", length); } StringWriter writer = new StringWriter( Math.min(Constants.IO_BUFFER_SIZE, length)); try (Reader reader = value.getReader()) { IOUtils.skipFully(reader, pos - 1); IOUtils.copyAndCloseInput(reader, writer, length); } return writer.toString(); } catch (Exception e) { throw logAndConvert(e); } } /** * Fills the Clob. This is only supported for new, empty Clob objects that * were created with Connection.createClob() or createNClob(). The position * must be 1, meaning the whole Clob data is set. * * @param pos where to start writing (the first character is at position 1) * @param str the string to add * @return the length of the added text * @throws SQLException on failure */ @Override public int setString(long pos, String str) throws SQLException { try { if (isDebugEnabled()) { debugCode("setString(" + pos + ", " + quote(str) + ')'); } checkEditable(); if (pos != 1) { throw DbException.getInvalidValueException("pos", pos); } else if (str == null) { throw DbException.getInvalidValueException("str", str); } completeWrite(conn.createClob(new StringReader(str), -1)); return str.length(); } catch (Exception e) { throw logAndConvert(e); } } /** * Fills the Clob. This is only supported for new, empty Clob objects that * were created with Connection.createClob() or createNClob(). The position * must be 1, meaning the whole Clob data is set. * * @param pos where to start writing (the first character is at position 1) * @param str the string to add * @param offset the string offset * @param len the number of characters to read * @return the length of the added text */ @Override public int setString(long pos, String str, int offset, int len) throws SQLException { try { if (isDebugEnabled()) { debugCode("setString(" + pos + ", " + quote(str) + ", " + offset + ", " + len + ')'); } checkEditable(); if (pos != 1) { throw DbException.getInvalidValueException("pos", pos); } else if (str == null) { throw DbException.getInvalidValueException("str", str); } completeWrite(conn.createClob(new RangeReader(new StringReader(str), offset, len), -1)); return (int) value.getType().getPrecision(); } catch (Exception e) { throw logAndConvert(e); } } /** * [Not supported] Searches a pattern and return the position. */ @Override public long position(String pattern, long start) throws SQLException { throw unsupported("LOB search"); } /** * [Not supported] Searches a pattern and return the position. */ @Override public long position(Clob clobPattern, long start) throws SQLException { throw unsupported("LOB search"); } /** * Returns the reader, starting from an offset. * * @param pos 1-based offset * @param length length of requested area * @return the reader */ @Override public Reader getCharacterStream(long pos, long length) throws SQLException { try { if (isDebugEnabled()) { debugCode("getCharacterStream(" + pos + ", " + length + ')'); } checkReadable(); if (state == State.NEW) { if (pos != 1) { throw DbException.getInvalidValueException("pos", pos); } if (length != 0) { throw DbException.getInvalidValueException("length", pos); } } return value.getReader(pos, length); } catch (Exception e) { throw logAndConvert(e); } } }
Detected license expression

      
    
Detected license expression (SPDX)

      
    
Percentage of license text
1.35
Copyrights
- end_line: 2
  copyright: Copyright 2004-2023 H2 Group. Multiple-Licensed
  start_line: 2
Holders
- holder: H2 Group. Multiple-Licensed
  end_line: 2
  start_line: 2
Authors

      
    
License expression License clue details
(mpl-2.0 OR epl-1.0) AND proprietary-license {'score': 20.37, 'matcher': '3-seq', 'end_line': 3, 'rule_url': 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/mpl-2.0_or_epl-1.0_and_proprietary-license_2.RULE', 'from_file': None, 'start_line': 2, 'matched_text': ' * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,\n * and the EPL 1.0 (https://h2database.com/html/license.html).', 'match_coverage': 20.37, 'matched_length': 11, 'rule_relevance': 100, 'rule_identifier': 'mpl-2.0_or_epl-1.0_and_proprietary-license_2.RULE', 'license_expression': '(mpl-2.0 OR epl-1.0) AND proprietary-license', 'license_expression_spdx': '(MPL-2.0 OR EPL-1.0) AND LicenseRef-scancode-proprietary-license'}
URL Start line End line
https://h2database.com/html/license.html 3 3
Package URL License Primary language
pkg:osgi/com.h2database.source@2.2.220