<commit_before>package info.lofei.android.torch.Util;

import android.hardware.Camera;

import info.lofei.android.torch.Exception.TorchUnavailableException;

/**
 * @author <EMAIL>
 * @version 1.0.0
 *          lofei 2014-10-20 下午6:02
 * @package info.lofei.android.torch.Util
 * @copyright Copyright (C) 2012-2020 DuoTin Network Technology Co.,LTD
 */
public class TorchUtil {

    private static Camera sCamera;

    public static void turnOn() throws TorchUnavailableException {
        try {
            if (sCamera == null) {
                sCamera = Camera.open();
            }
            Camera.Parameters p = sCamera.getParameters();
            p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
            sCamera.setParameters(p);
            sCamera.startPreview();
        } catch (RuntimeException e) {
            throw new TorchUnavailableException(e);
        }
    }

    public static void turnOff() throws TorchUnavailableException {
        try {
            if (sCamera == null) {
                sCamera = Camera.open();
            }<commit_msg>fix bug :can't turn on with Nexus 5<commit_after>package info.lofei.android.torch.Util;

import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.os.Build;

import java.io.IOException;
import java.util.List;

import info.lofei.android.torch.Exception.TorchUnavailableException;

/**
 * @author <EMAIL>
 * @version 1.0.0
 *          lofei 2014-10-20 下午6:02
 * @package info.lofei.android.torch.Util
 * @copyright Copyright (C) 2012-2020 DuoTin Network Technology Co.,LTD
 */
public class TorchUtil {

    private static Camera sCamera;

    public static void turnOn() throws TorchUnavailableException {
        try {
            if (sCamera == null) {
                sCamera = Camera.open();
            }
            Camera.Parameters p = sCamera.getParameters();

            p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);

            sCamera.setParameters(p);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ) {
                sCamera.setPreviewTexture(new SurfaceTexture(0));
            }
            sCamera.startPreview();
        } catch (RuntimeException e) {
            throw new TorchUnavailableException(e);
        }catch (IOException e) {
            throw new TorchUnavailableException(e);
        }
    }

    public static void turnOff() throws TorchUnavailableException {
        try {
            if (sCamera == null) {
                sCamera = Camera.open();
            }
{'fraction_non_alphanumeric': 0.1, 'fraction_numerical': 0.01818181818181818, 'mean_word_length': 2.2827496757457846, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '5321081', 'n_tokens_mistral': 769, 'n_tokens_neox': 722, 'n_words': 158}