Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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 "License"); you may not use this file except in compliance 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 "AS IS" BASIS, 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.mahout.df;
 
 
 import  org.apache.hadoop.fs.FileSystem;
 import  org.apache.hadoop.fs.Path;
Utility class that contains various helper methods
 
 public class DFUtils {
   private DFUtils() {
   }

  
Writes an Node[] into a DataOutput

Parameters:
out
array
Throws:
IOException
 
   public static void writeArray(DataOutput outNode[] array)
       throws IOException {
     out.writeInt(array.length);
     for (Node w : array) {
       w.write(out);
     }
   }
  
  
Reads a Node[] from a DataInput

Parameters:
in
Returns:
Throws:
IOException
 
   public static Node[] readNodeArray(DataInput inthrows IOException {
     int length = in.readInt();
     Node[] nodes = new Node[length];
     for (int index = 0; index < lengthindex++) {
       nodes[index] = Node.read(in);
     }
 
     return nodes;
   }

  
Writes a double[] into a DataOutput

Parameters:
out
array
Throws:
IOException
 
   public static void writeArray(DataOutput outdouble[] array)
       throws IOException {
     out.writeInt(array.length);
     for (double value : array) {
       out.writeDouble(value);
     }
   }

  
Reads a double[] from a DataInput

Parameters:
in
Returns:
Throws:
IOException
 
   public static double[] readDoubleArray(DataInput inthrows IOException {
     int length = in.readInt();
     double[] array = new double[length];
     for (int index = 0; index < lengthindex++) {
       array[index] = in.readDouble();
     }
 
     return array;
   }

  
Writes an int[] into a DataOutput

Parameters:
out
array
Throws:
IOException
  public static void writeArray(DataOutput outint[] arraythrows IOException {
    out.writeInt(array.length);
    for (int value : array) {
      out.writeInt(value);
    }
  }

  
Reads an int[] from a DataInput

Parameters:
in
Returns:
Throws:
IOException
  public static int[] readIntArray(DataInput inthrows IOException {
    int length = in.readInt();
    int[] array = new int[length];
    for (int index = 0; index < lengthindex++) {
      array[index] = in.readInt();
    }
    return array;
  }

  
Return a list of all files in the output directory

Parameters:
fs
outputPath
Returns:
Throws:
IOException
RuntimeException if no file is found
  public static Path[] listOutputFiles(FileSystem fs, Path outputPath)
      throws IOException {
    Path[] outfiles = OutputUtils.listOutputFiles(fsoutputPath);
    if (outfiles.length == 0) {
      throw new IOException("No output found !");
    }
    return outfiles;
  }

  
Formats a time interval in milliseconds to a String in the form "hours:minutes:seconds:millis"

Parameters:
milli
Returns:
  public static String elapsedTime(long milli) {
    long seconds = milli / 1000;
    milli = milli % 1000;
  
    long minutes = seconds / 60;
    seconds = seconds % 60;
  
    long hours = minutes / 60;
    minutes = minutes % 60;
  
    return hours + "h " + minutes + "m " + seconds + "s " + milli;
  }
New to GrepCode? Check out our FAQ X