77范文网 - 专业文章范例文档资料分享平台

hadoop单机部署、集群部署及win7本地Eclipse远程配置管理(4)

来源:网络收集 时间:2019-06-05 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

* Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * \ * with the License. You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an \

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */

package org.apache.hadoop.fs;

import java.io.*;

import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile;

import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.permission.FsAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.io.IOUtils;

import org.apache.hadoop.io.nativeio.NativeIO; import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.Shell;

import org.apache.hadoop.util.Shell.ShellCommandExecutor; /**

* A collection of file-processing util methods */

public class FileUtil {

private static final Log LOG = LogFactory.getLog(FileUtil.class); /**

* convert an array of FileStatus to an array of Path *

* @param stats

* an array of FileStatus objects

* @return an array of paths corresponding to the input */

public static Path[] stat2Paths(FileStatus[] stats) { if (stats == null) return null;

Path[] ret = new Path[stats.length]; for (int i = 0; i < stats.length; ++i) { ret[i] = stats[i].getPath(); } return ret; } /**

* convert an array of FileStatus to an array of Path. * If stats if null, return path * @param stats

* an array of FileStatus objects * @param path

* default path to return in stats is null * @return an array of paths corresponding to the input */

public static Path[] stat2Paths(FileStatus[] stats, Path path) { if (stats == null)

return new Path[]{path}; else

return stat2Paths(stats); } /**

* Delete a directory and all its contents. If

* we return false, the directory may be partially-deleted. */

public static boolean fullyDelete(File dir) throws IOException { if (!fullyDeleteContents(dir)) { return false; }

return dir.delete(); } /**

* Delete the contents of a directory, not the directory itself. If * we return false, the directory may be partially-deleted. */

public static boolean fullyDeleteContents(File dir) throws IOException { boolean deletionSucceeded = true; File contents[] = dir.listFiles(); if (contents != null) {

for (int i = 0; i < contents.length; i++) { if (contents[i].isFile()) { if (!contents[i].delete()) { deletionSucceeded = false;

continue; // continue deletion of other files/dirs under dir } } else {

//try deleting the directory // this might be a symlink boolean b = false; b = contents[i].delete(); if (b){

//this was indeed a symlink or an empty directory

continue; }

// if not an empty directory or symlink let // fullydelete handle it. if (!fullyDelete(contents[i])) { deletionSucceeded = false;

continue; // continue deletion of other files/dirs under dir } } } }

return deletionSucceeded; } /**

* Recursively delete a directory. *

* @param fs {@link FileSystem} on which the path is present * @param dir directory to recursively delete * @throws IOException

* @deprecated Use {@link FileSystem#delete(Path, boolean)} */

@Deprecated

public static void fullyDelete(FileSystem fs, Path dir) throws IOException { fs.delete(dir, true); } //

// If the destination is a subdirectory of the source, then // generate exception //

private static void checkDependencies(FileSystem srcFS, Path src,

FileSystem dstFS,

Path dst)

throws IOException { if (srcFS == dstFS) {

String srcq = src.makeQualified(srcFS).toString() + Path.SEPARATOR; String dstq = dst.makeQualified(dstFS).toString() + Path.SEPARATOR; if (dstq.startsWith(srcq)) {

if (srcq.length() == dstq.length()) {

throw new IOException(\ } else {

throw new IOException(\ dst); } } } }

/** Copy files between FileSystems. */

public static boolean copy(FileSystem srcFS, Path src, FileSystem dstFS, Path dst, boolean deleteSource,

Configuration conf) throws IOException { return copy(srcFS, src, dstFS, dst, deleteSource, true, conf); }

public static boolean copy(FileSystem srcFS, Path[] srcs, FileSystem dstFS, Path dst, boolean deleteSource,

boolean overwrite, Configuration conf) throws IOException { boolean gotException = false; boolean returnVal = true;

StringBuffer exceptions = new StringBuffer();

if (srcs.length == 1)

return copy(srcFS, srcs[0], dstFS, dst, deleteSource, overwrite, conf);

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库hadoop单机部署、集群部署及win7本地Eclipse远程配置管理(4)在线全文阅读。

hadoop单机部署、集群部署及win7本地Eclipse远程配置管理(4).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/650579.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: