<commit_before>/**
 * 
 */
package org.lodder.subtools.sublibrary.util.http;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.lodder.subtools.sublibrary.logging.Logger;

import com.dropbox.core.DbxClient;
import com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.DbxWriteMode;

/**
 * @author lodder
 * 
 */
public class DropBoxClient {

  private static DropBoxClient dbc;
  private DbxClient dbxClient;
  private String locationOffset = "/Ondertitels/PrivateRepo/";
  private String unSortedLocationOffset = "/Ondertitels/Unsorted/";

  DropBoxClient() {
    dropboxInit();
  }

  public static DropBoxClient getDropBoxClient() {
    if (dbc == null) dbc = new DropBoxClient();
    return dbc;
  }

  private void dropboxInit() {
    final String accessToken = "<KEY>";

    DbxRequestConfig config =
        new DbxRequestConfig("PersonalDownload/1.0", java.util.Locale.getDefault().toString());

    dbxClient = new DbxClient(config, accessToken);
  }

  public boolean doDownloadFile(String location, File output) {
    boolean success = false;
    try (FileOutputStream outputStream = new FileOutputStream(output)){
      dbxClient.getFile(locationOffset + location, null, outputStream);
      success = true;
      outputStream.close();
    } catch (DbxException e) {
      Logger.instance.error(Logger.stack2String(e));
    } catch (IOException e) {
      Logger.instance.error(Logger.stack2String(e));
    }
    return success;
  }

  public void put(File inputFile, String filename, String languageCode) {
    FileInputStream inputStream = null;
    try {
      inputStream = new FileInputStream(inputFile);
      dbxClient.uploadFile(unSortedLocationOffset + "/" + languageCode + "/" + filename,
          DbxWriteMode.add(), inputFile.length(), inputStream);
    } catch (DbxException e) {
      Logger.instance.error(Logger.stack2String(e));
    } catch (IOException e) {
      Logger.instance.error(Logger.stack2String(e));
    } finally {
      if (inputStream != null) {
        try {
          inputStream.close();
        } catch (IOException e) {
          Logger.instance.error(Logger.stack2String(e));
        }
      }
    }
  }

  /**
   * @param location
   * @return
   */
  public String getFile(String location) {
    String content = "";
    try {
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      dbxClient.getFile(location, null, outputStream);
      content = outputStream.toString("UTF-8");
      outputStream.close();
    } catch (DbxException e) {
      Logger.instance.error(Logger.stack2String(e));
    } catch (IOException e) {
      Logger.instance.error(Logger.stack2String(e));
    }
    return content;
  }

}<commit_msg>Convert DropBoxClient from old logger to new LOGGER slf4j<commit_after>/**
 * 
 */
package org.lodder.subtools.sublibrary.util.http;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dropbox.core.DbxClient;
import com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.DbxWriteMode;

/**
 * @author lodder
 * 
 */
public class DropBoxClient {

  private static DropBoxClient dbc;
  private DbxClient dbxClient;
  private String locationOffset = "/Ondertitels/PrivateRepo/";
  private String unSortedLocationOffset = "/Ondertitels/Unsorted/";

  private static final Logger LOGGER = LoggerFactory.getLogger(DropBoxClient.class);

  DropBoxClient() {
    dropboxInit();
  }

  public static DropBoxClient getDropBoxClient() {
    if (dbc == null) dbc = new DropBoxClient();
    return dbc;
  }

  private void dropboxInit() {
    final String accessToken = "<KEY>";

    DbxRequestConfig config =
        new DbxRequestConfig("PersonalDownload/1.0", java.util.Locale.getDefault().toString());

    dbxClient = new DbxClient(config, accessToken);
  }

  public boolean doDownloadFile(String location, File output) {
    boolean success = false;
    try (FileOutputStream outputStream = new FileOutputStream(output)) {
      dbxClient.getFile(locationOffset + location, null, outputStream);
      success = true;
      outputStream.close();
    } catch (DbxException | IOException e) {
      LOGGER.error("doDownloadFile", e);
    }
    return success;
  }

  public void put(File inputFile, String filename, String languageCode) {
    FileInputStream inputStream = null;
    try {
      inputStream = new FileInputStream(inputFile);
      dbxClient.uploadFile(unSortedLocationOffset + "/" + languageCode + "/" + filename,
          DbxWriteMode.add(), inputFile.length(), inputStream);
    } catch (DbxException | IOException e) {
      LOGGER.error("put", e);
    } finally {
      if (inputStream != null) {
        try {
          inputStream.close();
        } catch (IOException e) {
          LOGGER.error("put close inputStream", e);
        }
      }
    }
  }

  /**
   * @param location
   * @return
   */
  public String getFile(String location) {
    String content = "";
    try {
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      dbxClient.getFile(location, null, outputStream);
      content = outputStream.toString("UTF-8");
      outputStream.close();
    } catch (DbxException | IOException e) {
      LOGGER.error("getFile", e);
    }
    return content;
  }

}
{'fraction_non_alphanumeric': 0.1146805455850682, 'fraction_numerical': 0.002871500358937545, 'mean_word_length': 3.3744113029827316, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7593746', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1643, 'n_words': 359}