不使用mapreduce将普通java代码转换为hadoop代码?

不使用mapreduce将普通java代码转换为hadoop代码?,java,hadoop,compression,hdfs,Java,Hadoop,Compression,Hdfs,我目前正在研究hadoop。我想把我的java代码转换成hadoop。我希望我的代码与hdfs一起工作。i、 我的代码是正常的文件系统,我希望它与hdfs(高清文件系统)的工作。我希望下面的代码在hadoop(hd文件系统)中工作 我建议您开始阅读和理解MapReduce代码的外观及其必须实现的功能: 然后你就会明白,没有“转换”。在一个非常高级的视图中,MapReduce Java代码是一种将代码分为两个阶段进行构造的方法:Map和Reduce 根据您的示例,您似乎希望使用并行计算来解算/压

我目前正在研究hadoop。我想把我的java代码转换成hadoop。我希望我的代码与hdfs一起工作。i、 我的代码是正常的文件系统,我希望它与hdfs(高清文件系统)的工作。我希望下面的代码在hadoop(hd文件系统)中工作


我建议您开始阅读和理解MapReduce代码的外观及其必须实现的功能:

然后你就会明白,没有“转换”。在一个非常高级的视图中,MapReduce Java代码是一种将代码分为两个阶段进行构造的方法:Map和Reduce


根据您的示例,您似乎希望使用并行计算来解算/压缩大量文件,因此您应该尝试将MapReduce代码编写为解算/压缩文件的两步过程。抱歉,我从来没有遇到过压缩算法。

这里给出了一个Java代码示例和处理Hadoop文件系统的示例:

你可以把这个作为参考

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

public class GZIPExample {

    public static void gzip() {
        int i = new File("/media/0052ADF152ADEC1A/all splits").list().length;
        System.out.println(i + "here");
        while (i > 0) {
            String file = "/media/0052ADF152ADEC1A/all splits/File" + i + ".txt";
            String gzipFile = "/media/0052ADF152ADEC1A/compress/Filegz" + i + ".gz";
            String newFile = "/media/0052ADF152ADEC1A/all/hadoop ebooks/test1.txt";

            compressGzipFile(file, gzipFile);

            decompressGzipFile(gzipFile, newFile);
            i--;
        }
    }

    private static void decompressGzipFile(String gzipFile, String newFile) {
        try {
            FileInputStream fis = new FileInputStream(gzipFile);
            GZIPInputStream gis = new GZIPInputStream(fis);
            FileOutputStream fos = new FileOutputStream(newFile);
            byte[] buffer = new byte[1024];
            int len;
            while ((len = gis.read(buffer)) != -1) {
                fos.write(buffer, 0, len);
            }
            //close resources
            fos.close();
            gis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private static void compressGzipFile(String file, String gzipFile) {
        try {
            FileInputStream fis = new FileInputStream(file);
            FileOutputStream fos = new FileOutputStream(gzipFile);
            GZIPOutputStream gzipOS = new GZIPOutputStream(fos);
            byte[] buffer = new byte[1024];
            int len;
            while ((len = fis.read(buffer)) != -1) {
                gzipOS.write(buffer, 0, len);
            }
            //close resources
            gzipOS.close();
            fos.close();
            fis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}