semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
@Override
    public void runTask(HashMap pjobParameters) throws Exception {
        if (hasRequiredResources(isSubTask())) {
            File lfileSource = new File(getSource());
            File lfileTarget = new File(getTarget());
            FileChannel lfisInput = null;
            FileChannel lfosOutput = null;
            try {
                int mbCount = 64;
                boolean lblnDone = false;
                while (!lblnDone) {
                    lfisInput = new FileInputStream(lfileSource).getChannel();
                    lfosOutput = new FileOutputStream(lfileTarget).getChannel();
                    try {
                        int maxCount = (mbCount * 1024 * 1024) - (32 * 1024);
                        long size = lfisInput.size();
                        long position = 0;
                        while (position < size) {
                            position += lfisInput.transferTo(position, maxCount, lfosOutput);
                        }
                        lblnDone = true;
                    } catch (IOException lioXcp) {
                        getLog().warn(lioXcp);
                        if (lioXcp.getMessage().contains("Insufficient system resources exist to complete the requested servic")) {
                            mbCount--;
                            getLog().debug("Dropped resource count down to [" + mbCount + "]");
                            if (mbCount == 0) {
                                lblnDone = true;
                            }
                            if (lfisInput != null) {
                                lfisInput.close();
                            }
                            if (lfosOutput != null) {
                                lfosOutput.close();
                            }
                        } else {
                            throw lioXcp;
                        }
                    }
                }
            } finally {
                if (lfisInput != null) {
                    lfisInput.close();
                }
                if (lfosOutput != null) {
                    lfosOutput.close();
                }
            }
        }
    }
public static void writeInputStreamToFile(final InputStream stream, final File target) {
        long size = 0;
        FileOutputStream fileOut;
        try {
            fileOut = new FileOutputStream(target);
            size = IOUtils.copyLarge(stream, fileOut);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (log.isInfoEnabled()) {
            log.info("Wrote " + size + " bytes to " + target.getAbsolutePath());
        } else {
            System.out.println("Wrote " + size + " bytes to " + target.getAbsolutePath());
        }
    }
public static long writeInputStreamToOutputStream(final InputStream in, final OutputStream out) {
        long size = 0;
        try {
            size = IOUtils.copyLarge(in, out);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        return size;
    }
@Test
    public void testExactCopySize() throws IOException {
        final int size = Byte.SIZE + RANDOMIZER.nextInt(TEST_DATA.length - Long.SIZE);
        final InputStream in = new ByteArrayInputStream(TEST_DATA);
        final ByteArrayOutputStream out = new ByteArrayOutputStream(size);
        final int cpySize = ExtraIOUtils.copy(in, out, size);
        assertEquals("Mismatched copy size", size, cpySize);
        final byte[] subArray = ArrayUtils.subarray(TEST_DATA, 0, size), outArray = out.toByteArray();
        assertArrayEquals("Mismatched data", subArray, outArray);
    }
@Test
    public void testCopyOverSize() throws IOException {
        final InputStream in = new ByteArrayInputStream(TEST_DATA);
        final ByteArrayOutputStream out = new ByteArrayOutputStream(TEST_DATA.length);
        final int cpySize = ExtraIOUtils.copy(in, out, TEST_DATA.length + Long.SIZE);
        assertEquals("Mismatched copy size", TEST_DATA.length, cpySize);
        final byte[] outArray = out.toByteArray();
        assertArrayEquals("Mismatched data", TEST_DATA, outArray);
    }
@Test
    public void testCopyUnknownSize() throws IOException {
        final InputStream in = new ByteArrayInputStream(TEST_DATA);
        final ByteArrayOutputStream out = new ByteArrayOutputStream(TEST_DATA.length);
        final int cpySize = ExtraIOUtils.copy(in, out, (-1));
        assertEquals("Mismatched copy size", TEST_DATA.length, cpySize);
        final byte[] outArray = out.toByteArray();
        assertArrayEquals("Mismatched data", TEST_DATA, outArray);
    }
private List _getWeathersFromYahoo(String city) {
        System.out.println("== get weather information of " + city + " from yahoo ==");
        try {
            URL url = new URL(URL + cities.get(city).toString());
            InputStream input = url.openStream();
            SAXParserFactory factory = SAXParserFactory.newInstance();
            factory.setNamespaceAware(false);
            SAXParser parser = factory.newSAXParser();
            YahooHandler yh = new YahooHandler();
            yh.setCity(city);
            parser.parse(input, yh);
            return yh.getWeathers();
        } catch (MalformedURLException e) {
            throw new WeatherException("MalformedURLException");
        } catch (IOException e) {
            throw new WeatherException("无法读取数据。");
        } catch (ParserConfigurationException e) {
            throw new WeatherException("ParserConfigurationException");
        } catch (SAXException e) {
            throw new WeatherException("数据格式错误，无法解析。");
        }
    }
public static void copy(String srcFilename, String destFilename) throws IOException {
        int bytes_read = 0;
        byte[] buffer = new byte[512];
        FileInputStream fin = null;
        FileOutputStream fout = null;
        try {
            fin = new FileInputStream(srcFilename);
            try {
                fout = new FileOutputStream(destFilename);
                while ((bytes_read = fin.read(buffer)) != -1) {
                    fout.write(buffer, 0, bytes_read);
                }
            } finally {
                try {
                    if (fout != null) {
                        fout.close();
                        fout = null;
                    }
                } catch (IOException e) {
                }
            }
        } finally {
            try {
                if (fin != null) {
                    fin.close();
                    fin = null;
                }
            } catch (IOException e) {
            }
        }
    }
public static int load(Context context, URL url) throws Exception {
        int texture[] = new int[1];
        GLES20.glGenTextures(1, texture, 0);
        int textureId = texture[0];
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
        InputStream is = url.openStream();
        Bitmap tmpBmp;
        try {
            tmpBmp = BitmapFactory.decodeStream(is);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
            }
        }
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR_MIPMAP_NEAREST);
        MyGLUtils.checkGlError("glTexParameterf GL_TEXTURE_MIN_FILTER");
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
        MyGLUtils.checkGlError("glTexParameterf GL_TEXTURE_MAG_FILTER");
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, tmpBmp, 0);
        MyGLUtils.checkGlError("texImage2D");
        GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
        MyGLUtils.checkGlError("glGenerateMipmap");
        tmpBmp.recycle();
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
        return textureId;
    }
public static void copyFile(File in, File out, boolean append) throws IOException {
        FileChannel inChannel = new FileInputStream(in).getChannel();
        FileChannel outChannel = new FileOutputStream(out, append).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (IOException e) {
            throw e;
        } finally {
            if (inChannel != null) inChannel.close();
            if (outChannel != null) outChannel.close();
        }
    }
private String hash(String clearPassword) {
        if (salt == 0) return null;
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA1");
        } catch (NoSuchAlgorithmException e) {
            throw new AssertionError("Can't find the SHA1 algorithm in the java.security package");
        }
        String saltString = String.valueOf(salt);
        md.update(saltString.getBytes());
        md.update(clearPassword.getBytes());
        byte[] digestBytes = md.digest();
        StringBuffer digestSB = new StringBuffer();
        for (int i = 0; i < digestBytes.length; i++) {
            int lowNibble = digestBytes[i] & 0x0f;
            int highNibble = (digestBytes[i] >> 4) & 0x0f;
            digestSB.append(Integer.toHexString(highNibble));
            digestSB.append(Integer.toHexString(lowNibble));
        }
        String digestStr = digestSB.toString();
        return digestStr;
    }
public static String getContents(String urlStr) throws Exception {
        String contents = "";
        URL url = new URL(urlStr);
        URLConnection openConnection = url.openConnection();
        final char[] buffer = new char[1024 * 1024];
        StringBuilder out = new StringBuilder();
        Reader in = new InputStreamReader(openConnection.getInputStream(), "UTF-8");
        int read;
        do {
            read = in.read(buffer, 0, buffer.length);
            if (read > 0) {
                out.append(buffer, 0, read);
            }
        } while (read >= 0);
        contents = out.toString();
        return contents;
    }
public static String download(String urlStr, String folder, String title) {
        String result = "";
        try {
            long startTime = System.currentTimeMillis();
            URL url = new URL(urlStr);
            url.openConnection();
            InputStream reader = url.openStream();
            FileOutputStream writer = new FileOutputStream(folder + File.separator + title);
            byte[] buffer = new byte[1024 * 1024];
            int totalBytesRead = 0;
            int bytesRead = 0;
            while ((bytesRead = reader.read(buffer)) > 0) {
                writer.write(buffer, 0, bytesRead);
                buffer = new byte[153600];
                totalBytesRead += bytesRead;
            }
            long endTime = System.currentTimeMillis();
            result = "Done. " + (new Integer(totalBytesRead).toString()) + " bytes read (" + (new Long(endTime - startTime).toString()) + " millseconds).\n";
            writer.close();
            reader.close();
        } catch (Exception e) {
            result = "Can not download. " + folder + File.separator + title + ":\n" + e.getMessage();
        }
        return result;
    }
public static String generate(boolean secure, boolean sep) throws UnknownHostException {
        MessageDigest messagedigest;
        StringBuilder stringbuffer = new StringBuilder();
        try {
            messagedigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException nosuchalgorithmexception) {
            throw new RuntimeException(nosuchalgorithmexception);
        }
        StringBuffer stringbuffer2;
        InetAddress inetaddress = InetAddress.getLocalHost();
        long l = System.currentTimeMillis();
        long l1 = 0L;
        if (secure) l1 = _secureRand.nextLong(); else l1 = _rand.nextLong();
        stringbuffer.append(inetaddress.toString());
        stringbuffer.append(":");
        stringbuffer.append(Long.toString(l));
        stringbuffer.append(":");
        stringbuffer.append(Long.toString(l1));
        messagedigest.update(stringbuffer.toString().getBytes());
        byte abyte0[] = messagedigest.digest();
        StringBuffer stringbuffer1 = new StringBuffer();
        for (int i = 0; i < abyte0.length; i++) {
            int j = abyte0[i] & 0xff;
            if (j < 16) stringbuffer1.append('0');
            stringbuffer1.append(Integer.toHexString(j));
        }
        String s = stringbuffer1.toString();
        stringbuffer2 = new StringBuffer();
        if (sep) {
            stringbuffer2.append(s.substring(0, 8));
            stringbuffer2.append("-");
            stringbuffer2.append(s.substring(8, 12));
            stringbuffer2.append("-");
            stringbuffer2.append(s.substring(12, 16));
            stringbuffer2.append("-");
            stringbuffer2.append(s.substring(16, 20));
            stringbuffer2.append("-");
            stringbuffer2.append(s.substring(20));
            return stringbuffer2.toString();
        } else {
            return s;
        }
    }
private void writeFile(File file, String fileName) {
        try {
            FileInputStream fin = new FileInputStream(file);
            FileOutputStream fout = new FileOutputStream(dirTableModel.getDirectory().getAbsolutePath() + File.separator + fileName);
            int val;
            while ((val = fin.read()) != -1) fout.write(val);
            fin.close();
            fout.close();
            dirTableModel.reset();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public int getResponseCode(URI uri) {
        int response = -1;
        try {
            URL url = uri.toURL();
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            response = connection.getResponseCode();
        } catch (MalformedURLException m) {
            throw new MalformedURLException("URL not correct");
        } catch (IOException e) {
            throw new IOException("can open connection");
        } finally {
            return response;
        }
    }
private static void copyFile(File src, File dest, int bufSize, boolean force) throws IOException {
        if (dest.exists()) {
            if (force) {
                dest.delete();
            } else {
                throw new IOException("Cannot overwrite existing file: " + dest.getName());
            }
        }
        byte[] buffer = new byte[bufSize];
        int read = 0;
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(src);
            out = new FileOutputStream(dest);
            while (true) {
                read = in.read(buffer);
                if (read == -1) {
                    break;
                }
                out.write(buffer, 0, read);
            }
        } finally {
            if (in != null) {
                try {
                    in.close();
                } finally {
                    if (out != null) {
                        out.close();
                    }
                }
            }
        }
    }
private static void copy(String fromFileName, String toFileName) throws IOException {
        File fromFile = new File(fromFileName);
        File toFile = new File(toFileName);
        if (!fromFile.exists()) throw new IOException("FileCopy: " + "no such source file: " + fromFileName);
        if (!fromFile.isFile()) throw new IOException("FileCopy: " + "can't copy directory: " + fromFileName);
        if (!fromFile.canRead()) throw new IOException("FileCopy: " + "source file is unreadable: " + fromFileName);
        if (toFile.isDirectory()) toFile = new File(toFile, fromFile.getName());
        if (toFile.exists()) {
            if (!toFile.canWrite()) throw new IOException("FileCopy: destination file is unwriteable: " + toFileName);
            System.out.flush();
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            String response = in.readLine();
            if (!response.equals("Y") && !response.equals("y")) throw new IOException("FileCopy: existing file was not overwritten.");
        } else {
            String parent = toFile.getParent();
            if (parent == null) parent = System.getProperty("user.dir");
            File dir = new File(parent);
            if (!dir.exists()) throw new IOException("FileCopy: " + "destination directory doesn't exist: " + parent);
            if (dir.isFile()) throw new IOException("FileCopy: " + "destination is not a directory: " + parent);
            if (!dir.canWrite()) throw new IOException("FileCopy: " + "destination directory is unwriteable: " + parent);
        }
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(fromFile);
            to = new FileOutputStream(toFile);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead);
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
                ;
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
                ;
            }
        }
    }
public static void copyFile(File in, File out) throws IOException {
        FileChannel inChannel = new FileInputStream(in).getChannel();
        FileChannel outChannel = new FileOutputStream(out).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (IOException e) {
            throw e;
        } finally {
            if (inChannel != null) inChannel.close();
            if (outChannel != null) outChannel.close();
        }
    }
public static void copyFile(File file, File dest_file) throws FileNotFoundException, IOException {
        DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
        DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(dest_file)));
        byte[] buffer = new byte[1024];
        int read;
        while ((read = in.read(buffer)) > 0) {
            out.write(buffer, 0, read);
        }
        in.close();
        out.close();
    }
protected void loadText(final Element elem) {
        final String urlAttr = elem.getAttributeValue("url");
        if (urlAttr != null) {
            String result = "";
            try {
                final URL url = new URL(DatabaseViewerManager.baseURL, urlAttr);
                final BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
                String line = reader.readLine();
                while (line != null) {
                    result += line + "\n";
                    line = reader.readLine();
                }
                elem.addContent(result);
                elem.removeAttribute("url");
            } catch (final Exception e) {
                throw new RuntimeException("Could not insert text template for database viewer from file", e);
            }
        }
    }
@Test
    public void testWriteModel() {
        Model model = new Model();
        model.setName("MY_MODEL1");
        Stereotype st1 = new Stereotype();
        st1.setName("Pirulito1");
        PackageObject p1 = new PackageObject("p1");
        ClassType type1 = new ClassType("Class1");
        type1.setStereotype(st1);
        type1.addMethod(new Method("doSomething"));
        p1.add(type1);
        ClassType type2 = new ClassType("Class2");
        Method m2 = new Method("doSomethingElse");
        m2.setType(type1);
        type2.addMethod(m2);
        p1.add(type2);
        Generalization g = new Generalization();
        g.setSource(type1);
        g.setTarget(type1);
        p1.add(g);
        model.add(p1);
        ModelWriter writer = new ModelWriter();
        try {
            File modelFile = new File("target", "test.model");
            writer.write(model, modelFile);
            File xmlFile = new File("target", "test.xml");
            xmlFile.createNewFile();
            IOUtils.copy(new GZIPInputStream(new FileInputStream(modelFile)), new FileOutputStream(xmlFile));
        } catch (IOException e) {
            log.error(e.getMessage(), e);
            Assert.fail(e.getMessage());
        }
    }
public InputStream open(String filename) throws IOException {
        URL url = TemplateLoader.resolveURL("cms/" + filename);
        if (url != null) return url.openStream();
        url = TemplateLoader.resolveURL(filename);
        if (url != null) return url.openStream();
        return null;
    }
public void run() {
        OutputStream out = null;
        InputStream in = null;
        boolean success = false;
        String absoluteFileName = "";
        try {
            String fileName = getFileName(softwareLocation);
            File downloadFolder = new File(Properties.downloadFolder);
            if (downloadFolder.exists()) {
                if (downloadFolder.isDirectory()) {
                    fileName = downloadFolder.getPath() + File.separator + fileName;
                }
            } else {
                downloadFolder.mkdir();
                fileName = downloadFolder.getPath() + File.separator + fileName;
            }
            File softwareFile = new File(fileName);
            absoluteFileName = softwareFile.getAbsolutePath();
            if (softwareFile.exists() && softwareFile.length() == softwareSize) {
                XohmLogger.debugPrintln("Software file already exists. Exiting...");
                listener.downloadComplete(true, softwareName, absoluteFileName);
                return;
            } else {
                try {
                    File[] oldFiles = downloadFolder.listFiles();
                    for (int i = 0; i < oldFiles.length; i++) {
                        oldFiles[i].delete();
                    }
                } catch (Exception ex) {
                }
            }
            File softwareTempFile = File.createTempFile("XOHMCM", null);
            URL url = new URL(softwareLocation);
            out = new BufferedOutputStream(new FileOutputStream(softwareTempFile));
            URLConnection connection = url.openConnection();
            in = connection.getInputStream();
            listener.downloadStarted(softwareName);
            byte[] buffer = new byte[1024];
            int numRead;
            long numWritten = 0;
            while ((numRead = in.read(buffer)) != -1) {
                out.write(buffer, 0, numRead);
                numWritten += numRead;
                listener.downloadProgressNotification(softwareName, numWritten, softwareSize);
            }
            out.flush();
            out.close();
            in.close();
            if (copyFile(softwareTempFile, softwareFile)) {
                XohmLogger.debugPrintln("Download complete: " + absoluteFileName + "\t" + numWritten);
                success = true;
                softwareTempFile.delete();
            }
        } catch (Exception ex) {
            XohmLogger.warningPrintln("Software Update download failed - " + ex.getMessage(), null, null);
            ex.printStackTrace();
        }
        listener.downloadComplete(success, softwareName, absoluteFileName);
    }