Tabnine Logo
IOUtils
Code IndexAdd Tabnine to your IDE (free)

How to use
IOUtils
in
org.apache.zookeeper.common

Best Java code snippets using org.apache.zookeeper.common.IOUtils (Showing top 14 results out of 315)

origin: apache/zookeeper

IOUtils.closeStream(out);
origin: apache/zookeeper

/**
 * Copies from one stream to another.
 * 
 * @param in
 *            InputStrem to read from
 * @param out
 *            OutputStream to write to
 * @param buffSize
 *            the size of the buffer
 * @param close
 *            whether or not close the InputStream and OutputStream at the
 *            end. The streams are closed in the finally clause.
 */
public static void copyBytes(InputStream in, OutputStream out,
    int buffSize, boolean close) throws IOException {
  try {
    copyBytes(in, out, buffSize);
    if (close) {
      out.close();
      out = null;
      in.close();
      in = null;
    }
  } finally {
    if (close) {
      closeStream(out);
      closeStream(in);
    }
  }
}
origin: apache/zookeeper

/**
 * Closes the stream ignoring {@link IOException}. Must only be called in
 * cleaning up from exception handlers.
 * 
 * @param stream
 *            the Stream to close
 */
public static void closeStream(Closeable stream) {
  cleanup(null, stream);
}
origin: apache/zookeeper

public static String readFile(File file) throws IOException {
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
  try {
    IOUtils.copyBytes(is, os, 1024, true);
  } finally {
    is.close();
  }
  return os.toString();
}
origin: org.apache.zookeeper/zookeeper

IOUtils.closeStream(out);
origin: org.apache.zookeeper/zookeeper

/**
 * Copies from one stream to another.
 * 
 * @param in
 *            InputStrem to read from
 * @param out
 *            OutputStream to write to
 * @param buffSize
 *            the size of the buffer
 * @param close
 *            whether or not close the InputStream and OutputStream at the
 *            end. The streams are closed in the finally clause.
 */
public static void copyBytes(InputStream in, OutputStream out,
    int buffSize, boolean close) throws IOException {
  try {
    copyBytes(in, out, buffSize);
    if (close) {
      out.close();
      out = null;
      in.close();
      in = null;
    }
  } finally {
    if (close) {
      closeStream(out);
      closeStream(in);
    }
  }
}
origin: org.apache.zookeeper/zookeeper

/**
 * Closes the stream ignoring {@link IOException}. Must only be called in
 * cleaning up from exception handlers.
 * 
 * @param stream
 *            the Stream to close
 */
public static void closeStream(Closeable stream) {
  cleanup(null, stream);
}
origin: apache/zookeeper

  /**
   * Builds a SetTraceMask request to be sent to the server, consisting of
   * "stmk" followed by the 8-byte long representation of the trace mask.
   *
   * @param mask trace mask to set
   * @return built request
   * @throws IOException if there is an I/O error
   */
  private String buildSetTraceMaskRequest(long mask) throws IOException {
    ByteArrayOutputStream baos = null;
    DataOutputStream dos = null;
    try {
      baos = new ByteArrayOutputStream();
      dos = new DataOutputStream(baos);
      dos.writeBytes("stmk");
      dos.writeLong(mask);
    } finally {
      IOUtils.closeStream(dos);
      IOUtils.closeStream(baos);
    }
    return new String(baos.toByteArray());
  }
}
origin: apache/zookeeper

  public static byte[] serializeRequest(Request request) {
    if (request == null || request.getHdr() == null) return null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
    try {
      request.getHdr().serialize(boa, "hdr");
      if (request.getTxn() != null) {
        request.getTxn().serialize(boa, "txn");
      }
    } catch (IOException e) {
      LOG.error("This really should be impossible", e);
    } finally {
      IOUtils.cleanup(LOG, baos);
    }
    return baos.toByteArray();
  }
}
origin: apache/zookeeper

IOUtils.closeStream(out);
origin: ShifuML/guagua

  private static void writeJobSplitMetaInfo(FileSystem fs, Path filename, FsPermission p, int splitMetaInfoVersion,
      JobSplit.SplitMetaInfo[] allSplitMetaInfo) throws IOException {
    // write the splits meta-info to a file for the job tracker
    FSDataOutputStream out = null;
    try {
      out = FileSystem.create(fs, filename, p);
      out.write(META_SPLIT_FILE_HEADER);
      WritableUtils.writeVInt(out, splitMetaInfoVersion);
      WritableUtils.writeVInt(out, allSplitMetaInfo.length);
      for(JobSplit.SplitMetaInfo splitMetaInfo: allSplitMetaInfo) {
        splitMetaInfo.write(out);
      }
    } finally {
      IOUtils.closeStream(out);
    }
  }
}
origin: ml.shifu/guagua-yarn

  private static void writeJobSplitMetaInfo(FileSystem fs, Path filename, FsPermission p, int splitMetaInfoVersion,
      JobSplit.SplitMetaInfo[] allSplitMetaInfo) throws IOException {
    // write the splits meta-info to a file for the job tracker
    FSDataOutputStream out = null;
    try {
      out = FileSystem.create(fs, filename, p);
      out.write(META_SPLIT_FILE_HEADER);
      WritableUtils.writeVInt(out, splitMetaInfoVersion);
      WritableUtils.writeVInt(out, allSplitMetaInfo.length);
      for(JobSplit.SplitMetaInfo splitMetaInfo: allSplitMetaInfo) {
        splitMetaInfo.write(out);
      }
    } finally {
      IOUtils.closeStream(out);
    }
  }
}
origin: ml.shifu/guagua-yarn

@SuppressWarnings({ "unchecked", "unused" })
private <T> T getSplitDetails(Path file, long offset) throws IOException {
  FileSystem fs = file.getFileSystem(getYarnConf());
  FSDataInputStream inFile = null;
  T split = null;
  try {
    inFile = fs.open(file);
    inFile.seek(offset);
    String className = Text.readString(inFile);
    Class<T> cls;
    try {
      cls = (Class<T>) getYarnConf().getClassByName(className);
    } catch (ClassNotFoundException ce) {
      IOException wrap = new IOException(String.format("Split class %s not found", className));
      wrap.initCause(ce);
      throw wrap;
    }
    SerializationFactory factory = new SerializationFactory(getYarnConf());
    Deserializer<T> deserializer = (Deserializer<T>) factory.getDeserializer(cls);
    deserializer.open(inFile);
    split = deserializer.deserialize(null);
  } finally {
    IOUtils.closeStream(inFile);
  }
  return split;
}
origin: ShifuML/guagua

@SuppressWarnings({ "unchecked", "unused" })
private <T> T getSplitDetails(Path file, long offset) throws IOException {
  FileSystem fs = file.getFileSystem(getYarnConf());
  FSDataInputStream inFile = null;
  T split = null;
  try {
    inFile = fs.open(file);
    inFile.seek(offset);
    String className = Text.readString(inFile);
    Class<T> cls;
    try {
      cls = (Class<T>) getYarnConf().getClassByName(className);
    } catch (ClassNotFoundException ce) {
      IOException wrap = new IOException(String.format("Split class %s not found", className));
      wrap.initCause(ce);
      throw wrap;
    }
    SerializationFactory factory = new SerializationFactory(getYarnConf());
    Deserializer<T> deserializer = (Deserializer<T>) factory.getDeserializer(cls);
    deserializer.open(inFile);
    split = deserializer.deserialize(null);
  } finally {
    IOUtils.closeStream(inFile);
  }
  return split;
}
org.apache.zookeeper.commonIOUtils

Most used methods

  • closeStream
    Closes the stream ignoring IOException. Must only be called in cleaning up from exception handlers.
  • copyBytes
    Copies from one stream to another.
  • cleanup
    Close the Closeable objects and ignore any IOException or null pointers. Must only be used for clean

Popular in Java

  • Making http requests using okhttp
  • getApplicationContext (Context)
  • findViewById (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • Option (scala)
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now