<commit_before>/*
 * Copyright 2008 Last.fm
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package fm.last.ivy.plugins.svnresolver;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;

/**
 * Operation that represents adding/updating a file in svn.
 */
public class PutOperation {

  /**
   * The file to put.
   */
  private File file;

  /**
   * Whether any existing file data in svn should be overwritten or not.
   */
  private boolean overwrite;

  /**
   * The contents of the file.
   */
  byte[] data;

  /**
   * The folder path of the file.
   */
  private String folderPath;

  /*
   * The full path to the file destination location in svn.
   */
  private String fullDestinationPath;

  /**
   * The name of the file (without any folder path).
   */
  private String fileName;

  /**
   * The svn base repository path, if not set it is assumed to be the path up to the first "/" in any paths.
   */
  private String baseRepositoryPath;

  /**
   * Constructs a new PutOperation.
   * 
   * @param file The file to be added/updated in svn.
   * @param destination The full svn destination path of the file.
   * @param overwrite Whether any existing file data should be overwritten or not.
   * @param baseRepositoryPath The SVN base repository path, if null, the base with will be assumed to be the path up to
   *          the first "/" in any svn paths (often the case).
   * @throws IOException If the file data cannot be read from disk or the file paths cannot be determined.
   */
  public PutOperation(File file, String destination, boolean overwrite, String baseRepositoryPath) throws IOException {
    this.file = file;
    if (file.getName().startsWith("ivytemp") || file.getAbsolutePath().startsWith(System.getProperty("java.io.tmpdir"))) {
      // most likely a checksum generated by ivy, we need to store file in memory as ivy deletes this
      // inbetween calls to put so it will be gone when we try publish transaction
      loadFileData();
    }
    this.fullDestinationPath = destination;
    this.overwrite = overwrite;
    this.baseRepositoryPath = baseRepositoryPath;
    try {
      determinePaths();
    } catch (SVNException e) {
      throw new IOException("Error determing paths from " + destination, e);
    }
  }

  /**
   * Loads the file data from disk into an in-memory byte array.
   * 
   * @throws IOException If an error occurs reading the file.
   */
  private void loadFileData() throws IOException {
    BufferedInputStream fileInputStream = null;<commit_msg>fixed typo in exception message<commit_after>/*
 * Copyright 2008 Last.fm
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package fm.last.ivy.plugins.svnresolver;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;

/**
 * Operation that represents adding/updating a file in svn.
 */
public class PutOperation {

  /**
   * The file to put.
   */
  private File file;

  /**
   * Whether any existing file data in svn should be overwritten or not.
   */
  private boolean overwrite;

  /**
   * The contents of the file.
   */
  byte[] data;

  /**
   * The folder path of the file.
   */
  private String folderPath;

  /*
   * The full path to the file destination location in svn.
   */
  private String fullDestinationPath;

  /**
   * The name of the file (without any folder path).
   */
  private String fileName;

  /**
   * The svn base repository path, if not set it is assumed to be the path up to the first "/" in any paths.
   */
  private String baseRepositoryPath;

  /**
   * Constructs a new PutOperation.
   * 
   * @param file The file to be added/updated in svn.
   * @param destination The full svn destination path of the file.
   * @param overwrite Whether any existing file data should be overwritten or not.
   * @param baseRepositoryPath The SVN base repository path, if null, the base with will be assumed to be the path up to
   *          the first "/" in any svn paths (often the case).
   * @throws IOException If the file data cannot be read from disk or the file paths cannot be determined.
   */
  public PutOperation(File file, String destination, boolean overwrite, String baseRepositoryPath) throws IOException {
    this.file = file;
    if (file.getName().startsWith("ivytemp") || file.getAbsolutePath().startsWith(System.getProperty("java.io.tmpdir"))) {
      // most likely a checksum generated by ivy, we need to store file in memory as ivy deletes this
      // inbetween calls to put so it will be gone when we try publish transaction
      loadFileData();
    }
    this.fullDestinationPath = destination;
    this.overwrite = overwrite;
    this.baseRepositoryPath = baseRepositoryPath;
    try {
      determinePaths();
    } catch (SVNException e) {
      throw new IOException("Error determining paths from " + destination, e);
    }
  }

  /**
   * Loads the file data from disk into an in-memory byte array.
   * 
   * @throws IOException If an error occurs reading the file.
   */
  private void loadFileData() throws IOException {
    BufferedInputStream fileInputStream = null;
{'fraction_non_alphanumeric': 0.08257741632780732, 'fraction_numerical': 0.0025023459493274947, 'mean_word_length': 3.0758444869343533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6437535', 'n_tokens_mistral': 1777, 'n_tokens_neox': 1751, 'n_words': 755}