<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def writetb(path, kvs, java_mem_mb=256):
 """Write typedbytes sequence file to HDFS given an iterator of KeyValue pairs :param path: HDFS path (string) :param kvs: Iterator of (key, value) :param java_mem_mb: Integer of java heap size in MB (default 256) :raises: IOError: An error occurred while saving the data. """

    read_fd, write_fd = os.pipe()
    read_fp = os.fdopen(read_fd, 'r')
    hstreaming = _find_hstreaming()
    cmd = 'hadoop jar %s loadtb %s' % (hstreaming, path)
    p = _hadoop_fs_command(cmd, stdin=read_fp, java_mem_mb=java_mem_mb)
    read_fp.close()
    with hadoopy.TypedBytesFile(write_fd=write_fd) as tb_fp:
        for kv in kvs:
            if p.poll() is not None:
                raise IOError('writetb: Hadoop process quit while we were sending it data.  Hadoop output below...\nstdout\n%s\nstderr\n%s' % p.communicate())
            tb_fp.write(kv)
        tb_fp.flush()
    p.wait()
    if p.returncode is not 0:
        raise IOError('writetb: Hadoop process returned [%d]. Hadoop output below...\nstderr\n%s' % (p.returncode, p.stderr.read()))