semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static boolean update(ItemNotaFiscal objINF) {
        final Connection c = DBConnection.getConnection();
        PreparedStatement pst = null;
        int result;
        CelulaFinanceira objCF = null;
        if (c == null) {
            return false;
        }
        if (objINF == null) {
            return false;
        }
        try {
            c.setAutoCommit(false);
            String sql = "";
            sql = "update item_nota_fiscal " + "set id_item_pedido = ? " + "where id_item_nota_fiscal = ?";
            pst = c.prepareStatement(sql);
            pst.setInt(1, objINF.getItemPedido().getCodigo());
            pst.setInt(2, objINF.getCodigo());
            result = pst.executeUpdate();
            if (result > 0) {
                if (objINF.getItemPedido().getCelulaFinanceira() != null) {
                    objCF = objINF.getItemPedido().getCelulaFinanceira();
                    objCF.atualizaGastoReal(objINF.getSubtotal());
                    if (CelulaFinanceiraDAO.update(objCF)) {
                    }
                }
            }
            c.commit();
        } catch (final SQLException e) {
            try {
                c.rollback();
            } catch (final Exception e1) {
                System.out.println("[ItemNotaFiscalDAO.update.rollback] Erro ao inserir -> " + e1.getMessage());
            }
            System.out.println("[ItemNotaFiscalDAO.update.insert] Erro ao inserir -> " + e.getMessage());
            result = 0;
        } finally {
            DBConnection.closePreparedStatement(pst);
            DBConnection.closeConnection(c);
        }
        if (result > 0) {
            return true;
        } else {
            return false;
        }
    }
public static URL toFileUrl(URL location) throws IOException {
        String protocol = location.getProtocol().intern();
        if (protocol != "jar") throw new IOException("cannot explode " + location);
        JarURLConnection juc = (JarURLConnection) location.openConnection();
        String path = juc.getEntryName();
        String parentPath = parentPathOf(path);
        File tempDir = createTempDir("jartemp");
        JarFile jarFile = juc.getJarFile();
        for (Enumeration<JarEntry> en = jarFile.entries(); en.hasMoreElements(); ) {
            ZipEntry entry = en.nextElement();
            if (entry.isDirectory()) continue;
            String entryPath = entry.getName();
            if (entryPath.startsWith(parentPath)) {
                File dest = new File(tempDir, entryPath);
                dest.getParentFile().mkdirs();
                InputStream in = jarFile.getInputStream(entry);
                OutputStream out = new FileOutputStream(dest);
                IOUtils.copy(in, out);
                dest.deleteOnExit();
            }
        }
        File realFile = new File(tempDir, path);
        return realFile.toURL();
    }
public static URL addToArchive(Pod pod, ZipOutputStream podArchiveOutputStream, String filename, InputStream source) throws IOException {
        ZipEntry entry = new ZipEntry(filename);
        podArchiveOutputStream.putNextEntry(entry);
        IOUtils.copy(source, podArchiveOutputStream);
        podArchiveOutputStream.closeEntry();
        return PodArchiveResolver.withinPodArchive(pod, filename);
    }
public ArrayList parseFile(File newfile) throws IOException {
        String s;
        String firstname;
        String secondname;
        String direction;
        String header;
        String name = null;
        String[] tokens;
        boolean readingHArrays = false;
        boolean readingVArrays = false;
        boolean readingAArrays = false;
        ArrayList xturndat = new ArrayList();
        ArrayList yturndat = new ArrayList();
        ArrayList ampturndat = new ArrayList();
        int nvalues;
        URL url = newfile.toURI().toURL();
        InputStream is = url.openStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        s = br.readLine();
        s = br.readLine();
        s = br.readLine();
        s = br.readLine();
        s = br.readLine();
        s = br.readLine();
        s = br.readLine();
        while ((s = br.readLine()) != null) {
            tokens = s.split("\\s+");
            nvalues = tokens.length;
            if (nvalues < 1) continue;
            firstname = tokens[0];
            secondname = tokens[1];
            if (secondname.startsWith("BPM")) {
                if (readingHArrays) dumpxData(name, xturndat); else if (readingVArrays) dumpyData(name, yturndat); else if (readingAArrays) dumpampData(name, ampturndat);
                direction = tokens[4];
                if (direction.equals("HORIZONTAL")) {
                    readingHArrays = true;
                    readingVArrays = false;
                    readingAArrays = false;
                }
                if (direction.equals("VERTICAL")) {
                    readingVArrays = true;
                    readingHArrays = false;
                    readingAArrays = false;
                }
                if (direction.equals("AMPLITUDE")) {
                    readingVArrays = false;
                    readingHArrays = false;
                    readingAArrays = true;
                }
                name = tokens[3];
                xturndat.clear();
                yturndat.clear();
                ampturndat.clear();
            }
            if (secondname.startsWith("WAVEFORM")) continue;
            if (nvalues == 3) {
                if (readingHArrays) xturndat.add(new Double(Double.parseDouble(tokens[2]))); else if (readingVArrays) yturndat.add(new Double(Double.parseDouble(tokens[2]))); else if (readingAArrays) ampturndat.add(new Double(Double.parseDouble(tokens[2])));
            }
        }
        dumpampData(name, ampturndat);
        data.add(xdatamap);
        data.add(ydatamap);
        data.add(ampdatamap);
        return data;
    }
@Override
    public LispObject execute(LispObject first, LispObject second) throws ConditionThrowable {
        Pathname zipfilePathname = coerceToPathname(first);
        byte[] buffer = new byte[4096];
        try {
            String zipfileNamestring = zipfilePathname.getNamestring();
            if (zipfileNamestring == null) return error(new SimpleError("Pathname has no namestring: " + zipfilePathname.writeToString()));
            ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfileNamestring));
            LispObject list = second;
            while (list != NIL) {
                Pathname pathname = coerceToPathname(list.CAR());
                String namestring = pathname.getNamestring();
                if (namestring == null) {
                    out.close();
                    File zipfile = new File(zipfileNamestring);
                    zipfile.delete();
                    return error(new SimpleError("Pathname has no namestring: " + pathname.writeToString()));
                }
                File file = new File(namestring);
                FileInputStream in = new FileInputStream(file);
                ZipEntry entry = new ZipEntry(file.getName());
                out.putNextEntry(entry);
                int n;
                while ((n = in.read(buffer)) > 0) out.write(buffer, 0, n);
                out.closeEntry();
                in.close();
                list = list.CDR();
            }
            out.close();
        } catch (IOException e) {
            return error(new LispError(e.getMessage()));
        }
        return zipfilePathname;
    }
private static void checkForUpdates() {
        LOGGER.debug("Checking for Updates");
        new Thread() {

            @Override
            public void run() {
                String lastVersion = null;
                try {
                    URL projectSite = new URL("http://code.google.com/p/g15lastfm/");
                    URLConnection urlC = projectSite.openConnection();
                    BufferedReader in = new BufferedReader(new InputStreamReader(urlC.getInputStream()));
                    String inputLine;
                    while ((inputLine = in.readLine()) != null) {
                        if (inputLine.contains("<strong>Current version:")) {
                            lastVersion = inputLine;
                            break;
                        }
                    }
                    in.close();
                    if (lastVersion != null && lastVersion.length() > 0) {
                        lastVersion = lastVersion.substring(lastVersion.indexOf("Current version:") + 16);
                        lastVersion = lastVersion.substring(0, lastVersion.indexOf("</strong>")).trim();
                        LOGGER.debug("last Version=" + lastVersion);
                    }
                    if (lastVersion.equals(getVersion())) LOGGER.debug("Not necessary to update"); else {
                        LOGGER.debug("New update found!");
                        SwingUtilities.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                if (JOptionPane.showConfirmDialog(null, "New version of G15Lastfm is available to download!", "New Update for G15Lastfm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                                    LOGGER.debug("User choose to update, opening browser.");
                                    Desktop desktop = Desktop.getDesktop();
                                    try {
                                        desktop.browse(new URI("http://code.google.com/p/g15lastfm/"));
                                    } catch (IOException e) {
                                        LOGGER.debug(e);
                                    } catch (URISyntaxException e) {
                                        LOGGER.debug(e);
                                    }
                                } else {
                                    LOGGER.debug("User choose to not update.");
                                }
                            }
                        });
                    }
                } catch (Exception e) {
                    LOGGER.debug(e);
                }
            }
        }.start();
    }
public void greatestIncrease(int maxIterations) {
        double[] increase = new double[numModels];
        int[] id = new int[numModels];
        Model md = new Model();
        double oldPerf = 1;
        for (int i = 0; i < numModels; i++) {
            md.addModel(models[i], false);
            increase[i] = oldPerf - md.getLoss();
            id[i] = i;
            oldPerf = md.getLoss();
        }
        for (int i = 0; i < numModels; i++) {
            for (int j = 0; j < numModels - 1 - i; j++) {
                if (increase[j] < increase[j + 1]) {
                    double increasetemp = increase[j];
                    int temp = id[j];
                    increase[j] = increase[j + 1];
                    id[j] = id[j + 1];
                    increase[j + 1] = increasetemp;
                    id[j + 1] = temp;
                }
            }
        }
        for (int i = 0; i < maxIterations; i++) {
            addToEnsemble(models[id[i]]);
            if (report) ensemble.report(models[id[i]].getName(), allSets);
            updateBestModel();
        }
    }
public static void init(Locale language) throws IOException {
        URL url = ClassLoader.getSystemResource("locales/" + language.getISO3Language() + ".properties");
        if (url == null) {
            throw new IOException("Could not load resource locales/" + language.getISO3Language() + ".properties");
        }
        PROPS.clear();
        PROPS.load(url.openStream());
    }
public String genPass() {
        String salto = "Z1mX502qLt2JTcW9MTDTGBBw8VBQQmY2";
        String clave = (int) (Math.random() * 10) + "" + (int) (Math.random() * 10) + "" + (int) (Math.random() * 10) + "" + (int) (Math.random() * 10) + "" + (int) (Math.random() * 10) + "" + (int) (Math.random() * 10) + "" + (int) (Math.random() * 10);
        password = clave;
        String claveConSalto = clave + salto;
        MessageDigest m = null;
        try {
            m = MessageDigest.getInstance("MD5");
            m.update(claveConSalto.getBytes("utf-8"), 0, claveConSalto.length());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String claveCifrada = new BigInteger(1, m.digest()).toString(16);
        return claveCifrada + ":" + salto;
    }
private boolean tryGet(String url, Hashtable<String, String> req) throws Exception {
        boolean result = false;
        Enumeration<String> keys = req.keys();
        String key;
        String value;
        String data = "";
        while (keys.hasMoreElements()) {
            key = keys.nextElement();
            value = req.get(key);
            data += URLEncoder.encode(key, "UTF-8") + "=" + URLEncoder.encode(value, "UTF-8") + "&";
        }
        URLConnection conn = new URL(url).openConnection();
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(data);
        wr.flush();
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null) {
            if (line != null) result = true;
        }
        wr.close();
        rd.close();
        result = true;
        return result;
    }
public static SimpleDataTable loadDataFromFile(URL urlMetadata, URL urlData) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(urlMetadata.openStream()));
        List<String> columnNamesList = new ArrayList<String>();
        String[] lineParts = null;
        String line;
        in.readLine();
        while ((line = in.readLine()) != null) {
            lineParts = line.split(",");
            columnNamesList.add(lineParts[0]);
        }
        String[] columnNamesArray = new String[columnNamesList.size()];
        int index = 0;
        for (String s : columnNamesList) {
            columnNamesArray[index] = s;
            index++;
        }
        SimpleDataTable table = new SimpleDataTable("tabulka s daty", columnNamesArray);
        in = new BufferedReader(new InputStreamReader(urlData.openStream()));
        lineParts = null;
        line = null;
        SimpleDataTableRow tableRow;
        double[] rowData;
        while ((line = in.readLine()) != null) {
            lineParts = line.split(",");
            rowData = new double[columnNamesList.size()];
            for (int i = 0; i < columnNamesArray.length; i++) {
                rowData[i] = Double.parseDouble(lineParts[i + 1]);
            }
            tableRow = new SimpleDataTableRow(rowData, lineParts[0]);
            table.add(tableRow);
        }
        return table;
    }
private static void loadManifests() {
        Perl5Util util = new Perl5Util();
        try {
            for (Enumeration e = classLoader.getResources("META-INF/MANIFEST.MF"); e.hasMoreElements(); ) {
                URL url = (URL) e.nextElement();
                if (util.match("/" + pluginPath.replace('\\', '/') + "/", url.getFile())) {
                    InputStream inputStream = url.openStream();
                    manifests.add(new Manifest(inputStream));
                    inputStream.close();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public void test_calculateLastModifiedSizeContent() {
        File file;
        String content = "Hello, world!";
        String expected;
        FileETag etag;
        try {
            file = File.createTempFile("temp", "txt");
            file.deleteOnExit();
            FileOutputStream out = new FileOutputStream(file);
            out.write(content.getBytes());
            out.flush();
            out.close();
            SimpleDateFormat date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
            long lastModified = date.parse("06/21/2007 11:19:36").getTime();
            file.setLastModified(lastModified);
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(content.getBytes());
            StringBuffer buffer = new StringBuffer();
            buffer.append(lastModified);
            buffer.append(content.length());
            expected = new String(Hex.encodeHex(messageDigest.digest(buffer.toString().getBytes())));
            etag = new FileETag();
            etag.setFlags(FileETag.FLAG_CONTENT | FileETag.FLAG_MTIME | FileETag.FLAG_SIZE);
            String value = etag.calculate(file);
            assertEquals("Unexpected value", expected, value);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            fail("Unexpected exception");
        } catch (IOException e) {
            e.printStackTrace();
            fail("Unexpected exception");
        } catch (ParseException e) {
            e.printStackTrace();
            fail("Unexpected exception");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            fail("Unexpected exception");
        }
    }
@Override
    public void render(Output output) throws IOException {
        output.setStatus(headersFile.getStatusCode(), headersFile.getStatusMessage());
        for (Entry<String, Set<String>> header : headersFile.getHeadersMap().entrySet()) {
            Set<String> values = header.getValue();
            for (String value : values) {
                output.addHeader(header.getKey(), value);
            }
        }
        if (file != null) {
            InputStream inputStream = new FileInputStream(file);
            try {
                output.open();
                OutputStream out = output.getOutputStream();
                IOUtils.copy(inputStream, out);
            } finally {
                inputStream.close();
                output.close();
            }
        }
    }
public static final InputStream openStream(Bundle bundle, IPath file, boolean localized) throws IOException {
        URL url = null;
        if (!localized) {
            url = findInPlugin(bundle, file);
            if (url == null) url = findInFragments(bundle, file);
        } else {
            url = FindSupport.find(bundle, file);
        }
        if (url != null) return url.openStream();
        throw new IOException("Cannot find " + file.toString());
    }
@Test
    public void test() throws Exception {
        InputStream is = this.getClass().getResourceAsStream("originAndDestination.xml");
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        IOUtils.copy(is, byteArrayOutputStream);
        TrafficModelDefinition def = MDFReader.read(byteArrayOutputStream.toByteArray());
        TrafficSimulationEngine se = new TrafficSimulationEngine();
        se.init(def);
        int linkId = 2;
        int segmentId = 0;
        Map<Integer, Set<Integer>> linkSegments = new HashMap<Integer, Set<Integer>>();
        Set<Integer> segments = new HashSet<Integer>();
        segments.add(segmentId);
        linkSegments.put(linkId, segments);
        FrameProperties frameProperties = new FrameProperties(linkSegments, new HashSet<Integer>());
        se.setFrameProperties(frameProperties);
        for (float time = 0; time < 60 * 10; time += 0.1f) {
            se.step(0.1f);
            for (RoadObject vehicle : se.getDynamicObjects()) {
                System.out.println(time + ": X=" + vehicle.getPosition() + "\tV=" + vehicle.getSpeed());
            }
        }
    }
public static void main(String[] args) throws IOException {
        FileOutputStream f = new FileOutputStream("test.zip");
        CheckedOutputStream csum = new CheckedOutputStream(f, new CRC32());
        ZipOutputStream zos = new ZipOutputStream(csum);
        BufferedOutputStream out = new BufferedOutputStream(zos);
        zos.setComment("A test of Java Zipping");
        for (String arg : args) {
            print("Writing file " + arg);
            BufferedReader in = new BufferedReader(new FileReader(arg));
            zos.putNextEntry(new ZipEntry(arg));
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.flush();
        }
        out.close();
        print("Checksum: " + csum.getChecksum().getValue());
        print("Reading file");
        FileInputStream fi = new FileInputStream("test.zip");
        CheckedInputStream csumi = new CheckedInputStream(fi, new CRC32());
        ZipInputStream in2 = new ZipInputStream(csumi);
        BufferedInputStream bis = new BufferedInputStream(in2);
        ZipEntry ze;
        while ((ze = in2.getNextEntry()) != null) {
            print("Reading file " + ze);
            int x;
            while ((x = bis.read()) != -1) {
                System.out.write(x);
            }
            if (args.length == 1) {
                print("Checksum: " + csumi.getChecksum().getValue());
            }
            bis.close();
        }
    }
protected void setUp() throws Exception {
        testOutputDirectory = new File(getClass().getResource("/").getPath());
        zipFile = new File(this.testOutputDirectory, "/plugin.zip");
        zipOutputDirectory = new File(this.testOutputDirectory, "zip");
        zipOutputDirectory.mkdir();
        logger.fine("zip dir created");
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile));
        zos.putNextEntry(new ZipEntry("css/"));
        zos.putNextEntry(new ZipEntry("css/system.properties"));
        System.getProperties().store(zos, null);
        zos.closeEntry();
        zos.putNextEntry(new ZipEntry("js/"));
        zos.putNextEntry(new ZipEntry("js/system.properties"));
        System.getProperties().store(zos, null);
        zos.closeEntry();
        zos.putNextEntry(new ZipEntry("WEB-INF/"));
        zos.putNextEntry(new ZipEntry("WEB-INF/classes/"));
        zos.putNextEntry(new ZipEntry("WEB-INF/classes/system.properties"));
        System.getProperties().store(zos, null);
        zos.closeEntry();
        zos.putNextEntry(new ZipEntry("WEB-INF/lib/"));
        zos.putNextEntry(new ZipEntry("WEB-INF/lib/mylib.jar"));
        File jarFile = new File(this.testOutputDirectory.getPath() + "/mylib.jar");
        JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile));
        jos.putNextEntry(new ZipEntry("vqwiki/"));
        jos.putNextEntry(new ZipEntry("vqwiki/plugins/"));
        jos.putNextEntry(new ZipEntry("vqwiki/plugins/system.properties"));
        System.getProperties().store(jos, null);
        jos.closeEntry();
        jos.close();
        IOUtils.copy(new FileInputStream(jarFile), zos);
        zos.closeEntry();
        zos.close();
        jarFile.delete();
    }
private VelocityEngine newVelocityEngine() {
        VelocityEngine velocityEngine = null;
        InputStream is = null;
        try {
            URL url = ClassPathUtils.getResource(VELOCITY_PROPS_FILE);
            is = url.openStream();
            Properties props = new Properties();
            props.load(is);
            velocityEngine = new VelocityEngine(props);
            velocityEngine.init();
        } catch (Exception e) {
            throw new RuntimeException("can not find velocity props file, file=" + VELOCITY_PROPS_FILE, e);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return velocityEngine;
    }