Java Code Examples for org.apache.hadoop.hdfs.DFSUtil#bytes2byteArray()

The following examples show how to use org.apache.hadoop.hdfs.DFSUtil#bytes2byteArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FSImageSerialization.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Reading the path from the image and converting it to byte[][] directly
 * this saves us an array copy and conversions to and from String
 * @param in input to read from
 * @return the array each element of which is a byte[] representation 
 *            of a path component
 * @throws IOException
 */
@SuppressWarnings("deprecation")
public static byte[][] readPathComponents(DataInput in)
    throws IOException {
  DeprecatedUTF8 ustr = TL_DATA.get().U_STR;
  
  ustr.readFields(in);
  return DFSUtil.bytes2byteArray(ustr.getBytes(),
    ustr.getLength(), (byte) Path.SEPARATOR_CHAR);
}
 
Example 2
Source File: TestPathComponents.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public void testString(String str) throws Exception {
  String pathString = str;
  byte[][] oldPathComponents = INode.getPathComponents(pathString);
  byte[][] newPathComponents = 
              DFSUtil.bytes2byteArray(pathString.getBytes(Charsets.UTF_8),
                                      (byte) Path.SEPARATOR_CHAR);
  if (oldPathComponents[0] == null) {
    assertTrue(oldPathComponents[0] == newPathComponents[0]);
  } else {
    assertTrue("Path components do not match for " + pathString,
                Arrays.deepEquals(oldPathComponents, newPathComponents));
  }
}
 
Example 3
Source File: FSImageSerialization.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Reading the path from the image and converting it to byte[][] directly
 * this saves us an array copy and conversions to and from String
 * @param in input to read from
 * @return the array each element of which is a byte[] representation 
 *            of a path component
 * @throws IOException
 */
@SuppressWarnings("deprecation")
public static byte[][] readPathComponents(DataInput in)
    throws IOException {
  DeprecatedUTF8 ustr = TL_DATA.get().U_STR;
  
  ustr.readFields(in);
  return DFSUtil.bytes2byteArray(ustr.getBytes(),
    ustr.getLength(), (byte) Path.SEPARATOR_CHAR);
}
 
Example 4
Source File: TestPathComponents.java    From big-c with Apache License 2.0 5 votes vote down vote up
public void testString(String str) throws Exception {
  String pathString = str;
  byte[][] oldPathComponents = INode.getPathComponents(pathString);
  byte[][] newPathComponents = 
              DFSUtil.bytes2byteArray(pathString.getBytes(Charsets.UTF_8),
                                      (byte) Path.SEPARATOR_CHAR);
  if (oldPathComponents[0] == null) {
    assertTrue(oldPathComponents[0] == newPathComponents[0]);
  } else {
    assertTrue("Path components do not match for " + pathString,
                Arrays.deepEquals(oldPathComponents, newPathComponents));
  }
}
 
Example 5
Source File: TestPathComponents.java    From RDFS with Apache License 2.0 5 votes vote down vote up
public void testString(String str) throws Exception {
  String pathString = str;
  byte[][] oldPathComponents = INode.getPathComponents(pathString);
  byte[][] newPathComponents = 
              DFSUtil.bytes2byteArray(pathString.getBytes("UTF-8"),
                                      (byte) Path.SEPARATOR_CHAR);
  if (oldPathComponents[0] == null) {
    assertTrue(oldPathComponents[0] == newPathComponents[0]);
  } else {
    assertTrue("Path components do not match for " + pathString,
                Arrays.deepEquals(oldPathComponents, newPathComponents));
  }
}
 
Example 6
Source File: FSImageSerialization.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
 * Reading the path from the image and converting it to byte[][] directly
 * this saves us an array copy and conversions to and from String
 * @param in
 * @return the array each element of which is a byte[] representation 
 *            of a path component
 * @throws IOException
 */
@SuppressWarnings("deprecation")
public static byte[][] readPathComponents(DataInputStream in)
    throws IOException {
  UTF8 ustr = TL_DATA.get().U_STR;
  
  ustr.readFields(in);
  return DFSUtil.bytes2byteArray(ustr.getBytes(),
    ustr.getLength(), (byte) Path.SEPARATOR_CHAR);
}
 
Example 7
Source File: INode.java    From RDFS with Apache License 2.0 2 votes vote down vote up
/**
 * Breaks file path into components.
 * @param path specified in byte[] format
 * @param len length of the path
 * @return array of byte arrays each of which represents 
 * a single path component.
 */
static byte[][] getPathComponents(byte[] path) {
  return DFSUtil.bytes2byteArray(path, path.length, (byte) Path.SEPARATOR_CHAR);
}