<commit_before>package org.byteworks.cbor.impl;

import java.io.IOException;
import java.io.OutputStream;

import org.byteworks.cbor.CBOROutputStream;
import org.byteworks.cbor.UInt;
import org.byteworks.cbor.UInt.UInt64;

public class CBOROutputStreamImpl implements CBOROutputStream {
  private static final int UINT_8 = 0x18;
  private static final int UINT_16 = 0x19;
  private static final int UINT_32 = 0x1a;
  private static final int UINT_64 = 0x1b;
  
  private OutputStream output;

  public CBOROutputStreamImpl(OutputStream output) {
    this.output = output;
  }

  @Override
  public void write(int b) throws IOException {
    writeByte(b);
  }

  @Override
  public void write(byte[] b) throws IOException {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Not implemented: write");
  }

  @Override
  public void write(byte[] b, int off, int len) throws IOException {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Not implemented: write");
  }

  @Override
  public void writeBoolean(boolean v) throws IOException {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Not implemented: writeBoolean");
  }

  @Override
  public void writeByte(int v) throws IOException {
    if (v < 24) 
      output.write(v);
    else {
      output.write(UINT_8);
      output.write(v);
    }
  }

  @Override
  public void writeShort(int v) throws IOException {
    output.write(UINT_16);
    output.write((v >>> 8) & 0xff);
    output.write(v & 0xff);
  }

  @Override
  public void writeChar(int v) throws IOException {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Not implemented: writeChar");
  }

  @Override
  public void writeInt(int v) throws IOException {
    output.write(UINT_32);
    output.write((v >>> 24) & 0xff);
    output.write((v >>> 16) & 0xff);
    output.write((v >>>  8) & 0xff);
    output.write(v & 0xff);    
  }

  @Override
  public void writeLong(long v) throws IOException {
    output.write(UINT_64);
    output.write((int)((v >> 56) & 0xff));
    output.write((int)((v >> 48) & 0xff));
    output.write((int)((v >> 40) & 0xff));
    output.write((int)((v >> 32) & 0xff));
    output.write((int)((v >> 24) & 0xff));
    output.write((int)((v >> 16) & 0xff));
    output.write((int)((v >> 8) & 0xff));
    output.write((int)(v & 0xff));
  }
<commit_msg>add writeChar() support<commit_after>package org.byteworks.cbor.impl;

import java.io.IOException;
import java.io.OutputStream;

import org.byteworks.cbor.CBOROutputStream;
import org.byteworks.cbor.UInt;
import org.byteworks.cbor.UInt.UInt64;

public class CBOROutputStreamImpl implements CBOROutputStream {
  private static final int UINT_8 = 0x18;
  private static final int UINT_16 = 0x19;
  private static final int UINT_32 = 0x1a;
  private static final int UINT_64 = 0x1b;
  
  private OutputStream output;

  public CBOROutputStreamImpl(OutputStream output) {
    this.output = output;
  }

  @Override
  public void write(int b) throws IOException {
    writeByte(b);
  }

  @Override
  public void write(byte[] b) throws IOException {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Not implemented: write");
  }

  @Override
  public void write(byte[] b, int off, int len) throws IOException {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Not implemented: write");
  }

  @Override
  public void writeBoolean(boolean v) throws IOException {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Not implemented: writeBoolean");
  }

  @Override
  public void writeByte(int v) throws IOException {
    if (v < 24) 
      output.write(v);
    else {
      output.write(UINT_8);
      output.write(v);
    }
  }

  @Override
  public void writeShort(int v) throws IOException {
    output.write(UINT_16);
    output.write((v >>> 8) & 0xff);
    output.write(v & 0xff);
  }

  @Override
  public void writeChar(int v) throws IOException {
    output.write(UINT_16);
    output.write((v >>> 8) & 0xff);
    output.write(v & 0xff);
  }

  @Override
  public void writeInt(int v) throws IOException {
    output.write(UINT_32);
    output.write((v >>> 24) & 0xff);
    output.write((v >>> 16) & 0xff);
    output.write((v >>>  8) & 0xff);
    output.write(v & 0xff);    
  }

  @Override
  public void writeLong(long v) throws IOException {
    output.write(UINT_64);
    output.write((int)((v >> 56) & 0xff));
    output.write((int)((v >> 48) & 0xff));
    output.write((int)((v >> 40) & 0xff));
    output.write((int)((v >> 32) & 0xff));
    output.write((int)((v >> 24) & 0xff));
    output.write((int)((v >> 16) & 0xff));
    output.write((int)((v >> 8) & 0xff));
    output.write((int)(v & 0xff));
  }

{'fraction_non_alphanumeric': 0.13126934984520125, 'fraction_numerical': 0.026212590299277607, 'mean_word_length': 3.478743068391867, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 58, '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': '4440792', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1517, 'n_words': 403}