semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void downloadTranslationsAndReload() {
        File languages = new File(this.translationsFile);
        try {
            URL languageURL = new URL(languageServer);
            InputStream is = languageURL.openStream();
            OutputStream os = new FileOutputStream(languages);
            byte[] read = new byte[512000];
            int bytesRead = 0;
            do {
                bytesRead = is.read(read);
                if (bytesRead > 0) {
                    os.write(read, 0, bytesRead);
                }
            } while (bytesRead > 0);
            is.close();
            os.close();
            this.loadTranslations();
        } catch (Exception e) {
            System.err.println("Remote languages file not found!");
            if (languages.exists()) {
                try {
                    XMLDecoder loader = new XMLDecoder(new FileInputStream(languages));
                    this.languages = (Hashtable) loader.readObject();
                    loader.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                    this.languages.put(naiveLanguage, new Hashtable());
                }
            } else this.languages.put(naiveLanguage, new Hashtable());
        }
    }
private void externalizeFiles(Document doc, File out) throws IOException {
        File[] files = doc.getImages();
        if (files.length > 0) {
            File dir = new File(out.getParentFile(), out.getName() + ".images");
            if (!dir.mkdirs()) throw new IOException("cannot create directory " + dir);
            if (dir.exists()) {
                for (int i = 0; i < files.length; i++) {
                    File file = files[i];
                    File copy = new File(dir, file.getName());
                    FileChannel from = null, to = null;
                    long count = -1;
                    try {
                        from = new FileInputStream(file).getChannel();
                        count = from.size();
                        to = new FileOutputStream(copy).getChannel();
                        from.transferTo(0, count, to);
                        doc.setImage(file, dir.getName() + "/" + copy.getName());
                    } catch (Throwable t) {
                        LOG.log(Level.WARNING, "Copying '" + file + "' to '" + copy + "' failed (size=" + count + ")", t);
                    } finally {
                        try {
                            to.close();
                        } catch (Throwable t) {
                        }
                        try {
                            from.close();
                        } catch (Throwable t) {
                        }
                    }
                }
            }
        }
    }
protected static void clearTables() throws SQLException {
        Connection conn = null;
        Statement stmt = null;
        try {
            conn = FidoDataSource.getConnection();
            conn.setAutoCommit(false);
            stmt = conn.createStatement();
            ClearData.clearTables(stmt);
            stmt.executeUpdate("delete from Objects");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (1, 'Money value')");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (2, 'Date')");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (3, 'Unix path')");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (4, 'Dos path')");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (5, 'Time')");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (6, 'IP address')");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (7, 'Internet hostname')");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (8, 'Number')");
            conn.commit();
        } catch (SQLException e) {
            if (conn != null) conn.rollback();
            throw e;
        } finally {
            if (stmt != null) stmt.close();
            if (conn != null) conn.close();
        }
    }
public final void close() throws IOException {
        if (dataStream == null) throw new NullPointerException("Write stream is null.");
        dataStream.flush();
        dataStream.close();
        dataStream = null;
        File tmpFile = new File(packPath + ".tmp");
        FileOutputStream packStream = new FileOutputStream(packPath);
        try {
            String nbFiles = Long.toString(currentNbFiles) + "\0";
            packStream.write(FLAT_PACK_HEADER.getBytes(Charsets.ISO_8859_1));
            structBufferWriter.flush();
            structBufferWriter.close();
            int headerSize = structBuffer.size() + nbFiles.length();
            packStream.write(Integer.toString(headerSize).getBytes(Charsets.ISO_8859_1));
            packStream.write('\0');
            packStream.write(nbFiles.getBytes(Charsets.ISO_8859_1));
            structBuffer.writeTo(packStream);
            structBufferWriter = null;
            structBuffer = null;
            FileInputStream in = new FileInputStream(tmpFile);
            try {
                byte[] buffer = new byte[FILE_COPY_BUFFER_LEN];
                int read;
                while ((read = in.read(buffer)) > 0) packStream.write(buffer, 0, read);
                packStream.flush();
                packStream.close();
            } finally {
                Utilities.closeStream(in);
            }
        } finally {
            Utilities.closeStream(packStream);
        }
        if (tmpFile.isFile()) Utilities.deleteFile(tmpFile);
        packPath = null;
        structBuffer = null;
    }
public RespID(PublicKey key) throws OCSPException {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA1");
            ASN1InputStream aIn = new ASN1InputStream(key.getEncoded());
            SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(aIn.readObject());
            digest.update(info.getPublicKeyData().getBytes());
            ASN1OctetString keyHash = new DEROctetString(digest.digest());
            this.id = new ResponderID(keyHash);
        } catch (Exception e) {
            throw new OCSPException("problem creating ID: " + e, e);
        }
    }
public static void copyFile(File source, File destination, boolean lazy) {
        if (!source.exists()) {
            return;
        }
        if (lazy) {
            String oldContent = null;
            try {
                oldContent = read(source);
            } catch (Exception e) {
                return;
            }
            String newContent = null;
            try {
                newContent = read(destination);
            } catch (Exception e) {
            }
            if (oldContent == null || !oldContent.equals(newContent)) {
                copyFile(source, destination, false);
            }
        } else {
            if ((destination.getParentFile() != null) && (!destination.getParentFile().exists())) {
                destination.getParentFile().mkdirs();
            }
            try {
                FileChannel srcChannel = new FileInputStream(source).getChannel();
                FileChannel dstChannel = new FileOutputStream(destination).getChannel();
                dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
                srcChannel.close();
                dstChannel.close();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    }
public static int copy(File src, int amount, File dst) {
        final int BUFFER_SIZE = 1024;
        int amountToRead = amount;
        boolean ok = true;
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new BufferedInputStream(new FileInputStream(src));
            out = new BufferedOutputStream(new FileOutputStream(dst));
            byte[] buf = new byte[BUFFER_SIZE];
            while (amountToRead > 0) {
                int read = in.read(buf, 0, Math.min(BUFFER_SIZE, amountToRead));
                if (read == -1) break;
                amountToRead -= read;
                out.write(buf, 0, read);
            }
        } catch (IOException e) {
        } finally {
            if (in != null) try {
                in.close();
            } catch (IOException e) {
            }
            if (out != null) {
                try {
                    out.flush();
                } catch (IOException e) {
                }
                try {
                    out.close();
                } catch (IOException e) {
                }
            }
        }
        return amount - amountToRead;
    }
@Test
    public void testRegister() {
        try {
            String username = "muchu";
            String password = "123";
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(password.getBytes());
            String passwordMd5 = new String(md5.digest());
            LogService logServiceMock = EasyMock.createMock(LogService.class);
            DbService dbServiceMock = EasyMock.createMock(DbService.class);
            userServ.setDbServ(dbServiceMock);
            userServ.setLogger(logServiceMock);
            IFeelerUser user = new FeelerUserImpl();
            user.setUsername(username);
            user.setPassword(passwordMd5);
            logServiceMock.info(DbUserServiceImpl.class, ">>>rigister " + username + "<<<");
            EasyMock.expect(dbServiceMock.queryFeelerUser(username)).andReturn(null);
            dbServiceMock.addFeelerUser(username, passwordMd5);
            logServiceMock.info(DbUserServiceImpl.class, ">>>identification " + username + "<<<");
            EasyMock.expect(dbServiceMock.queryFeelerUser(username)).andReturn(user);
            EasyMock.replay(dbServiceMock, logServiceMock);
            Assert.assertTrue(userServ.register(username, password));
            EasyMock.verify(dbServiceMock, logServiceMock);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
@Test
    public void testIdentification() {
        try {
            String username = "muchu";
            String password = "123";
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(password.getBytes());
            LogService logServiceMock = EasyMock.createMock(LogService.class);
            DbService dbServiceMock = EasyMock.createMock(DbService.class);
            userServ.setDbServ(dbServiceMock);
            userServ.setLogger(logServiceMock);
            logServiceMock.info(DbUserServiceImpl.class, ">>>identification " + username + "<<<");
            IFeelerUser user = new FeelerUserImpl();
            user.setUsername(username);
            user.setPassword(new String(md5.digest()));
            EasyMock.expect(dbServiceMock.queryFeelerUser(username)).andReturn(user);
            EasyMock.replay(logServiceMock, dbServiceMock);
            Assert.assertTrue(userServ.identification(username, password));
            EasyMock.verify(logServiceMock, dbServiceMock);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
protected HttpResponseImpl makeRequest(final HttpMethod m, final String requestId) {
        try {
            HttpResponseImpl ri = new HttpResponseImpl();
            ri.setRequestMethod(m);
            ri.setResponseCode(_client.executeMethod(m));
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            IOUtils.copy(m.getResponseBodyAsStream(), bos);
            ri.setResponseBody(bos.toByteArray());
            notifyOfRequestSuccess(requestId, m, ri);
            return ri;
        } catch (HttpException ex) {
            notifyOfRequestFailure(requestId, m, ex);
        } catch (IOException ex) {
            notifyOfRequestFailure(requestId, m, ex);
        }
        return null;
    }
private static void loadFromZip() {
        InputStream in = Resources.class.getResourceAsStream("data.zip");
        if (in == null) {
            return;
        }
        ZipInputStream zipIn = new ZipInputStream(in);
        try {
            while (true) {
                ZipEntry entry = zipIn.getNextEntry();
                if (entry == null) {
                    break;
                }
                String entryName = entry.getName();
                if (!entryName.startsWith("/")) {
                    entryName = "/" + entryName;
                }
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                IOUtils.copy(zipIn, out);
                zipIn.closeEntry();
                FILES.put(entryName, out.toByteArray());
            }
            zipIn.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
@Override
    public MD2Model loadModel(URL url, String skin) throws IOException, IncorrectFormatException, ParsingErrorException {
        boolean baseURLWasNull = setBaseURLFromModelURL(url);
        MD2Model model = loadModel(url.openStream(), skin);
        if (baseURLWasNull) {
            popBaseURL();
        }
        return (model);
    }
public void test() throws Exception {
        StorageStringWriter s = new StorageStringWriter(2048, "UTF-8");
        s.addText("Test");
        try {
            s.getOutputStream();
            fail("Should throw IOException as method not supported.");
        } catch (IOException e) {
        }
        s.getWriter().write("ing is important");
        s.close(ResponseStateOk.getInstance());
        assertEquals("Testing is important", s.getText());
        InputStream input = s.getInputStream();
        StringWriter writer = new StringWriter();
        IOUtils.copy(input, writer, "UTF-8");
        assertEquals("Testing is important", writer.toString());
        try {
            s.getWriter();
            fail("Should throw IOException as storage is closed.");
        } catch (IOException e) {
        }
    }
public static String urlContentToString(URL url, String encoding) throws IOException {
        String out = "";
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), Constants.ENCODING));
        String line;
        while ((line = in.readLine()) != null) {
            out += line;
        }
        in.close();
        return out;
    }
private static byte[] getHashValue(INewEntryDescriptor descriptor) {
        String timeStamp = Calendar.getInstance().getTime().toString();
        MessageDigest sha1;
        byte[] digest = { 0 };
        try {
            sha1 = MessageDigest.getInstance("SHA-1");
            sha1.update(descriptor.getContactName().getBytes());
            sha1.update(descriptor.getAlgorithmName().getBytes());
            sha1.update(descriptor.getProvider().getBytes());
            return digest = sha1.digest(timeStamp.getBytes());
        } catch (NoSuchAlgorithmException e) {
            logger.error("NoSuchAlgorithmException while digesting", e);
        }
        return digest;
    }
protected void handleUrl(URL url) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String s;
        boolean moreResults = false;
        while ((s = in.readLine()) != null) {
            if (s.indexOf("<h1>Search Results</h1>") > -1) {
                System.err.println("found severals result");
                moreResults = true;
            } else if (s.indexOf("Download <a href=") > -1) {
                if (s.indexOf("in JCAMP-DX format.") > -1) {
                    System.err.println("download masspec");
                    super.handleUrl(new URL((url.getProtocol() + "://" + url.getHost() + s.substring(s.indexOf("\"") + 1, s.lastIndexOf("\""))).replaceAll("amp;", "")));
                }
                moreResults = false;
            }
            if (moreResults == true) {
                if (s.indexOf("<li><a href=\"/cgi/cbook.cgi?ID") > -1) {
                    System.err.println("\tdownloading new url " + new URL((url.getProtocol() + "://" + url.getHost() + s.substring(s.indexOf("\"") + 1, s.lastIndexOf("\""))).replaceAll("amp;", "")));
                    this.handleUrl(new URL((url.getProtocol() + "://" + url.getHost() + s.substring(s.indexOf("\"") + 1, s.lastIndexOf("\""))).replaceAll("amp;", "")));
                }
            }
        }
    }
private int[] Tri(int[] pertinence, int taille) {
        boolean change = true;
        int tmp;
        while (change) {
            change = false;
            for (int i = 0; i < taille - 2; i++) {
                if (pertinence[i] < pertinence[i + 1]) {
                    tmp = pertinence[i];
                    pertinence[i] = pertinence[i + 1];
                    pertinence[i + 1] = tmp;
                    change = true;
                }
            }
        }
        return pertinence;
    }
private String digestPassword(String password) {
        StringBuffer hexString = new StringBuffer();
        try {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(password.getBytes());
            byte[] messageDigest = algorithm.digest();
            for (byte b : messageDigest) {
                hexString.append(Integer.toHexString(0xFF & b));
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return hexString.toString();
    }
public void testRoundTrip_1(String resource) throws Exception {
        long start1 = System.currentTimeMillis();
        File originalFile = File.createTempFile("RoundTripTest", "testRoundTrip_1");
        FileOutputStream fos = new FileOutputStream(originalFile);
        IOUtils.copy(getClass().getResourceAsStream(resource), fos);
        fos.close();
        long start2 = System.currentTimeMillis();
        IsoFile isoFile = new IsoFile(new FileInputStream(originalFile).getChannel());
        long start3 = System.currentTimeMillis();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        WritableByteChannel wbc = Channels.newChannel(baos);
        long start4 = System.currentTimeMillis();
        Walk.through(isoFile);
        long start5 = System.currentTimeMillis();
        isoFile.getBox(wbc);
        wbc.close();
        long start6 = System.currentTimeMillis();
        System.err.println("Preparing tmp copy took: " + (start2 - start1) + "ms");
        System.err.println("Parsing took           : " + (start3 - start2) + "ms");
        System.err.println("Writing took           : " + (start6 - start3) + "ms");
        System.err.println("Walking took           : " + (start5 - start4) + "ms");
        byte[] a = IOUtils.toByteArray(getClass().getResourceAsStream(resource));
        byte[] b = baos.toByteArray();
        Assert.assertArrayEquals(a, b);
    }
public static void main(String[] args) {
        System.out.println("Start filtering zgps...");
        final Config config = Gbl.createConfig(args);
        final String CONFIG_MODULE = "GPSFilterZGPS";
        File sourceFileSelectedStages = new File(config.findParam(CONFIG_MODULE, "sourceFileSelectedStages"));
        File sourceFileZGPS = new File(config.findParam(CONFIG_MODULE, "sourceFileZGPS"));
        File targetFile = new File(config.findParam(CONFIG_MODULE, "targetFile"));
        System.out.println("Start reading selected stages...");
        FilterZGPSSelectedStages selectedStages = new FilterZGPSSelectedStages();
        selectedStages.createSelectedStages(sourceFileSelectedStages);
        System.out.println("Done. " + selectedStages.getSelectedStages().size() + " stages were stored");
        System.out.println("Start reading and writing zgps...");
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(sourceFileZGPS)));
            BufferedWriter out = new BufferedWriter(new FileWriter(targetFile));
            out.write(in.readLine());
            out.newLine();
            String lineFromInputFile;
            while ((lineFromInputFile = in.readLine()) != null) {
                String[] entries = lineFromInputFile.split("\t");
                if (selectedStages.containsStage(Integer.parseInt(entries[0]), Integer.parseInt(entries[1]), Integer.parseInt(entries[2]))) {
                    out.write(lineFromInputFile);
                    out.newLine();
                    out.flush();
                }
            }
            in.close();
            out.close();
        } catch (FileNotFoundException e) {
            System.out.println("Could not find source file for selected stages.");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("IO Exception while reading or writing zgps.");
            e.printStackTrace();
        }
        System.out.println("Done.");
    }
private ShaderProgram loadShaderProgram() {
        ShaderProgram sp = null;
        String vertexProgram = null;
        String fragmentProgram = null;
        Shader[] shaders = new Shader[2];
        try {
            ClassLoader cl = this.getClass().getClassLoader();
            URL url = cl.getResource("Shaders/simple.vert");
            System.out.println("url " + url);
            InputStream inputSteam = cl.getResourceAsStream("Shaders/simple.vert");
            Reader reader = null;
            if (inputSteam != null) {
                reader = new InputStreamReader(inputSteam);
            } else {
                File file = new File("lib");
                URL url2 = new URL("jar:file:" + file.getAbsolutePath() + "/j3d-vrml97-i3mainz.jar!/Shaders/simple.vert");
                InputStream inputSteam2 = url2.openStream();
                reader = new InputStreamReader(inputSteam2);
            }
            char[] buffer = new char[10000];
            int len = reader.read(buffer);
            vertexProgram = new String(buffer);
            vertexProgram = vertexProgram.substring(0, len);
        } catch (Exception e) {
            System.err.println("could'nt load simple.vert");
            e.printStackTrace();
        }
        try {
            ClassLoader cl = this.getClass().getClassLoader();
            URL url = cl.getResource("Shaders/simple.frag");
            System.out.println("url " + url);
            InputStream inputSteam = cl.getResourceAsStream("Shaders/simple.frag");
            Reader reader = null;
            if (inputSteam != null) {
                reader = new InputStreamReader(inputSteam);
            } else {
                File file = new File("lib");
                URL url2 = new URL("jar:file:" + file.getAbsolutePath() + "/j3d-vrml97-i3mainz.jar!/Shaders/simple.frag");
                InputStream inputSteam2 = url2.openStream();
                reader = new InputStreamReader(inputSteam2);
            }
            char[] buffer = new char[10000];
            int len = reader.read(buffer);
            fragmentProgram = new String(buffer);
            fragmentProgram = fragmentProgram.substring(0, len);
        } catch (Exception e) {
            System.err.println("could'nt load simple.frag");
            e.printStackTrace();
        }
        if (vertexProgram != null && fragmentProgram != null) {
            shaders[0] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_VERTEX, vertexProgram);
            shaders[1] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_FRAGMENT, fragmentProgram);
            sp = new GLSLShaderProgram();
            sp.setShaders(shaders);
        }
        return sp;
    }