<commit_before>/* ============================================================
 * JRobin : Pure java implementation of RRDTool's functionality
 * ============================================================
 *
 * Project Info:  http://www.jrobin.org
 * Project Lead:  Sasa Markovic (<EMAIL>);
 *
 * (C) Copyright 2003, by <NAME>.
 *
 * Developers:    <NAME> (<EMAIL>)
 *                <NAME> (<EMAIL>)
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 */
package org.jrobin.core;

import java.io.IOException;

abstract class RrdPrimitive {
	
	private RrdUpdater parent;
	private long pointer;
	private int byteCount;
	
	RrdPrimitive(RrdUpdater parent, int byteCount) throws IOException {
		this.parent = parent;
		// this will set pointer and byteCount
		parent.getRrdFile().allocate(this, byteCount);
	}
	
	long getPointer() {
		return pointer;
	}

	void setPointer(long pointer) {
		this.pointer = pointer;
	}
	
	int getByteCount() {
		return byteCount;
	}
	
	void setByteCount(int byteCount) {
		this.byteCount = byteCount;
	}
	
	RrdUpdater getParent() {
		return parent;
	}
	
	RrdFile getRrdFile() {
		return parent.getRrdFile();
	}
	
	byte[] getBytes() throws IOException {
		byte[] b = new byte[byteCount];
		int bytesRead = parent.getRrdFile().read(b);
		if(bytesRead != byteCount) {
			throw new IOException("Could not read enough bytes (" + byteCount + 
				" bytes requested, " + bytesRead + " bytes obtained");
		}
		return b;
	}
	
}<commit_msg>Related classes (RrdInt, RrdLong, etc) are now properly rooted. RrdPrimtive class introduced as a base class for all classes mapped to a RRD file. Code should run slightly faster.<commit_after>/* ============================================================
 * JRobin : Pure java implementation of RRDTool's functionality
 * ============================================================
 *
 * Project Info:  http://www.jrobin.org
 * Project Lead:  <NAME> (<EMAIL>);
 *
 * (C) Copyright 2003, by <NAME>.
 *
 * Developers:    <NAME> (<EMAIL>)
 *                <NAME> (<EMAIL>)
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 */
package org.jrobin.core;

import java.io.IOException;

abstract class RrdPrimitive {
	
	private RrdUpdater parent;
	private long pointer;
	private int byteCount;
	
	RrdPrimitive(RrdUpdater parent, int byteCount) throws IOException {
		this.parent = parent;
		// this will set pointer and byteCount
		parent.getRrdFile().allocate(this, byteCount);
	}
	
	long getPointer() {
		return pointer;
	}

	void setPointer(long pointer) {
		this.pointer = pointer;
	}
	
	int getByteCount() {
		return byteCount;
	}
	
	void setByteCount(int byteCount) {
		this.byteCount = byteCount;
	}
	
	RrdUpdater getParent() {
		return parent;
	}
	
	RrdFile getRrdFile() {
		return parent.getRrdFile();
	}
	
	byte[] getBytes() throws IOException {
		byte[] b = new byte[byteCount];
		RrdFile rrdFile = getRrdFile();
		rrdFile.seek(pointer);
		int bytesRead = rrdFile.read(b);
		if(bytesRead != byteCount) {
			throw new IOException("Could not read enough bytes (" + byteCount + 
				" bytes requested, " + bytesRead + " bytes obtained");
		}
		return b;
	}

	void writeBytes(byte[] b) throws IOException {
		if(b.length != byteCount) {
			throw new IOException("Invalid number of bytes supplied (" + b.length +
				"), exactly " + byteCount + " needed");
		}
		RrdFile rrdFile = getRrdFile();
		rrdFile.seek(pointer);
		rrdFile.write(b);
	}

}
{'fraction_non_alphanumeric': 0.1430069196896624, 'fraction_numerical': 0.00838750262109457, 'mean_word_length': 3.9074074074074074, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3503556', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1352, 'n_words': 510}