<commit_before>package org.csstudio.logbook.olog;

import static edu.msu.nscl.olog.api.LogBuilder.log;
import static edu.msu.nscl.olog.api.LogbookBuilder.logbook;
import static edu.msu.nscl.olog.api.PropertyBuilder.property;
import static edu.msu.nscl.olog.api.TagBuilder.tag;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.csstudio.logbook.Attachment;
import org.csstudio.logbook.LogEntry;
import org.csstudio.logbook.Logbook;
import org.csstudio.logbook.LogbookClient;
import org.csstudio.logbook.Property;
import org.csstudio.logbook.Tag;

import com.google.common.base.Function;
import com.google.common.collect.Collections2;

import edu.msu.nscl.olog.api.Log;
import edu.msu.nscl.olog.api.LogBuilder;
import edu.msu.nscl.olog.api.OlogClient;
import edu.msu.nscl.olog.api.PropertyBuilder;

public class OlogLogbookClient implements LogbookClient {

	private final OlogClient reader;
	private final OlogClient writer;

	public OlogLogbookClient(OlogClient ologClient) {
		this.reader = ologClient;
		this.writer = ologClient;
	}

	public OlogLogbookClient(OlogClient reader, OlogClient writer) {
		this.reader = reader;
		this.writer = writer;
	}

	@Override
	public Collection<Logbook> listLogbooks() {
		return Collections.unmodifiableCollection(Collections2.transform(
				reader.listLogbooks(),
				new Function<edu.msu.nscl.olog.api.Logbook, Logbook>() {

					@Override
					public Logbook apply(edu.msu.nscl.olog.api.Logbook input) {
						return new OlogLogbook(input);
					}
				}));
	}

	@Override
	public Collection<Tag> listTags() {
		return Collections.unmodifiableCollection(Collections2.transform(
				reader.listTags(),
				new Function<edu.msu.nscl.olog.api.Tag, Tag>() {

					@Override
					public Tag apply(edu.msu.nscl.olog.api.Tag input) {
						return new OlogTag(input);
					}
				}));
	}

	@Override
	public Collection<Property> listProperties() {
		return Collections.unmodifiableCollection(Collections2.transform(
				reader.listProperties(),
				new Function<edu.msu.nscl.olog.api.Property, Property>() {

					@Override
					public Property apply(edu.msu.nscl.olog.api.Property input) {
						return new OlogPropery(input);
					}
				}));
	}

	@Override
	public Collection<Attachment> listAttachments(Object logId) {
		return Collections.unmodifiableCollection(Collections2.transform(
				reader.listAttachments((Long) logId),
				new Function<edu.msu.nscl.olog.api.Attachment, Attachment>() {

					@Override
					public Attachment apply(
							edu.msu.nscl.olog.api.Attachment input) {
						return new OlogAttachment(input);
					}
				}));
	}

	@Override
	public InputStream getAttachment(Object logId, String attachmentFileName) {
		return reader.getAttachment((Long) logId, attachmentFileName);
	}

	@Override
	public LogEntry findLogEntry(Object logId) throws Exception {
		Log log = reader.getLog((Long) logId);
		return new OlogEntry(log);
	}

	@Override
	public Collection<LogEntry> findLogEntries(
			Map<String, String> findAttributeMap) throws Exception {
		Collection<LogEntry> logEntries = new ArrayList<LogEntry>();
		Collection<Log> logs = reader.findLogs(findAttributeMap);
		for (Log log : logs) {
			logEntries.add(new OlogEntry(log));
		}
		return logEntries;
	}

	@Override
	public LogEntry createLogEntry(LogEntry logEntry) throws IOException {
		return new OlogEntry(writer.set(LogBuilder(logEntry)));
	}

	@Override
	public LogEntry updateLogEntry(LogEntry logEntry) throws Exception {
		return new OlogEntry(writer.update(LogBuilder(logEntry)));
	}

	@Override
	public Attachment addAttachment(Object logId, InputStream attachment) {

		File file;
		try {
			file = File.createTempFile(logId + "-attachment", null);
			// write the inputStream to a FileOutputStream
			OutputStream out = new FileOutputStream(file);
			int read = 0;
			byte[] bytes = new byte[1024];

			while ((read = attachment.read(bytes)) != -1) {
				out.write(bytes, 0, read);
			}
			attachment.close();
			out.flush();
			out.close();
			if (file != null)
				return new OlogAttachment(writer.add(file, (Long) logId));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();<commit_msg>..OlogLogbookClient: updating to match new API<commit_after>package org.csstudio.logbook.olog;

import static edu.msu.nscl.olog.api.LogBuilder.log;
import static edu.msu.nscl.olog.api.LogbookBuilder.logbook;
import static edu.msu.nscl.olog.api.PropertyBuilder.property;
import static edu.msu.nscl.olog.api.TagBuilder.tag;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.csstudio.logbook.Attachment;
import org.csstudio.logbook.LogEntry;
import org.csstudio.logbook.Logbook;
import org.csstudio.logbook.LogbookClient;
import org.csstudio.logbook.Property;
import org.csstudio.logbook.Tag;

import com.google.common.base.Function;
import com.google.common.collect.Collections2;

import edu.msu.nscl.olog.api.Log;
import edu.msu.nscl.olog.api.LogBuilder;
import edu.msu.nscl.olog.api.OlogClient;
import edu.msu.nscl.olog.api.PropertyBuilder;

public class OlogLogbookClient implements LogbookClient {

	private final OlogClient reader;
	private final OlogClient writer;

	public OlogLogbookClient(OlogClient ologClient) {
		this.reader = ologClient;
		this.writer = ologClient;
	}

	public OlogLogbookClient(OlogClient reader, OlogClient writer) {
		this.reader = reader;
		this.writer = writer;
	}

	@Override
	public Collection<Logbook> listLogbooks() {
		return Collections.unmodifiableCollection(Collections2.transform(
				reader.listLogbooks(),
				new Function<edu.msu.nscl.olog.api.Logbook, Logbook>() {

					@Override
					public Logbook apply(edu.msu.nscl.olog.api.Logbook input) {
						return new OlogLogbook(input);
					}
				}));
	}

	@Override
	public Collection<Tag> listTags() {
		return Collections.unmodifiableCollection(Collections2.transform(
				reader.listTags(),
				new Function<edu.msu.nscl.olog.api.Tag, Tag>() {

					@Override
					public Tag apply(edu.msu.nscl.olog.api.Tag input) {
						return new OlogTag(input);
					}
				}));
	}

	@Override
	public Collection<Property> listProperties() {
		return Collections.unmodifiableCollection(Collections2.transform(
				reader.listProperties(),
				new Function<edu.msu.nscl.olog.api.Property, Property>() {

					@Override
					public Property apply(edu.msu.nscl.olog.api.Property input) {
						return new OlogPropery(input);
					}
				}));
	}

	@Override
	public Collection<Attachment> listAttachments(Object logId) {
		return Collections.unmodifiableCollection(Collections2.transform(
				reader.listAttachments((Long) logId),
				new Function<edu.msu.nscl.olog.api.Attachment, Attachment>() {

					@Override
					public Attachment apply(
							edu.msu.nscl.olog.api.Attachment input) {
						return new OlogAttachment(input);
					}
				}));
	}

	@Override
	public InputStream getAttachment(Object logId, String attachmentFileName) {
		return reader.getAttachment((Long) logId, attachmentFileName);
	}

	@Override
	public LogEntry findLogEntry(Object logId) throws Exception {
		Log log = reader.getLog((Long) logId);
		return new OlogEntry(log);
	}

	@Override
	public Collection<LogEntry> findLogEntries(
			Map<String, String> findAttributeMap) throws Exception {
		Collection<LogEntry> logEntries = new ArrayList<LogEntry>();
		Collection<Log> logs = reader.findLogs(findAttributeMap);
		for (Log log : logs) {
			logEntries.add(new OlogEntry(log));
		}
		return logEntries;
	}

	@Override
	public LogEntry createLogEntry(LogEntry logEntry) throws IOException {
		return new OlogEntry(writer.set(LogBuilder(logEntry)));
	}

	@Override
	public LogEntry updateLogEntry(LogEntry logEntry) throws Exception {
		return new OlogEntry(writer.update(LogBuilder(logEntry)));
	}

	@Override
	public Attachment addAttachment(Object logId, InputStream attachment,
			String name) {

		File file;
		try {
			file = File.createTempFile(name, null);
			// write the inputStream to a FileOutputStream
			OutputStream out = new FileOutputStream(file);
			int read = 0;
			byte[] bytes = new byte[1024];

			while ((read = attachment.read(bytes)) != -1) {
				out.write(bytes, 0, read);
			}
			attachment.close();
			out.flush();
			out.close();
			if (file != null)
				return new OlogAttachment(writer.add(file, (Long) logId));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
{'fraction_non_alphanumeric': 0.1132286995515695, 'fraction_numerical': 0.0026905829596412557, 'mean_word_length': 4.374096385542169, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1896427', 'n_tokens_mistral': 3217, 'n_tokens_neox': 2850, 'n_words': 589}