当前位置: 首页>>代码示例>>Java>>正文


Java DataInputStream.close方法代码示例

本文整理汇总了Java中java.io.DataInputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java DataInputStream.close方法的具体用法?Java DataInputStream.close怎么用?Java DataInputStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.DataInputStream的用法示例。


在下文中一共展示了DataInputStream.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testHandleSpaceInPathAsProducedByEclipse

import java.io.DataInputStream; //导入方法依赖的package包/类
public void testHandleSpaceInPathAsProducedByEclipse() throws Exception {
    File d = new File(getWorkDir(), "space in path");
    d.mkdirs();
    File f = new File(d, "x.jar");
    JarOutputStream os = new JarOutputStream(new FileOutputStream(f));
    os.putNextEntry(new JarEntry("test.txt"));
    os.write(10);
    os.close();
    
    URL u = new URL("jar:" + f.toURL() + "!/test.txt");
    DataInputStream is = new DataInputStream(u.openStream());
    byte[] arr = new byte[100];
    is.readFully(arr, 0, 1);
    assertEquals("One byte", 10, arr[0]);
    is.close();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:ProxyURLStreamHandlerFactoryTest.java

示例2: getAnnotationDefault

import java.io.DataInputStream; //导入方法依赖的package包/类
/**
    * Returns the default annotation value for the element
    * defined by this method.  Null is returned if no default 
    * is specified for this element, or if the class that contains 
    * this method does not define an annotation type.
    */
   public ElementValue getAnnotationDefault() {
if (annotationDefault == notloadedAnnotationDefault) {
           annotationDefault = null;
    DataInputStream in = 
	attributes.getStream("AnnotationDefault"); // NOI18N
    if (in != null) {
	try {
	    annotationDefault = 
		ElementValue.load(in, classFile.constantPool, false);
	    in.close();
	} catch (IOException e) {
	    throw new InvalidClassFileAttributeException("invalid AnnotationDefault attribute", e);
	}
    }
}
       return annotationDefault;
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:Method.java

示例3: read

import java.io.DataInputStream; //导入方法依赖的package包/类
public static NBTTagCompound read(File fileIn) throws IOException
{
    if (!fileIn.exists())
    {
        return null;
    }
    else
    {
        DataInputStream datainputstream = new DataInputStream(new FileInputStream(fileIn));
        NBTTagCompound nbttagcompound;

        try
        {
            nbttagcompound = read(datainputstream, NBTSizeTracker.INFINITE);
        }
        finally
        {
            datainputstream.close();
        }

        return nbttagcompound;
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:24,代码来源:CompressedStreamTools.java

示例4: readCheckpointTime

import java.io.DataInputStream; //导入方法依赖的package包/类
/**
 * Determine the checkpoint time of the specified StorageDirectory
 *
 * @param sd StorageDirectory to check
 * @return If file exists and can be read, last checkpoint time. If not, 0L.
 * @throws IOException On errors processing file pointed to by sd
 */
static long readCheckpointTime(StorageDirectory sd) throws IOException {
  File timeFile = NNStorage.getStorageFile(sd, NameNodeFile.TIME);
  long timeStamp = 0L;
  if (timeFile.exists() && FileUtil.canRead(timeFile)) {
    DataInputStream in = new DataInputStream(new FileInputStream(timeFile));
    try {
      timeStamp = in.readLong();
      in.close();
      in = null;
    } finally {
      IOUtils.cleanup(LOG, in);
    }
  }
  return timeStamp;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:23,代码来源:FSImagePreTransactionalStorageInspector.java

示例5: readPartitions

import java.io.DataInputStream; //导入方法依赖的package包/类
/**
 * Read the cut points from the given sequence file.
 * @param fs the file system
 * @param p the path to read
 * @param job the job config
 * @return the strings to split the partitions on
 * @throws IOException
 */
private static Text[] readPartitions(FileSystem fs, Path p,
    Configuration conf) throws IOException {
  int reduces = conf.getInt(MRJobConfig.NUM_REDUCES, 1);
  Text[] result = new Text[reduces - 1];
  DataInputStream reader = fs.open(p);
  for(int i=0; i < reduces - 1; ++i) {
    result[i] = new Text();
    result[i].readFields(reader);
  }
  reader.close();
  return result;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:TeraSort.java

示例6: getValue

import java.io.DataInputStream; //导入方法依赖的package包/类
/**
 * Copy value into user-supplied buffer. User supplied buffer must be
 * large enough to hold the whole value (starting from the offset). The
 * value part of the key-value pair pointed by the current cursor is not
 * cached and can only be examined once. Calling any of the following
 * functions more than once without moving the cursor will result in
 * exception: {@link #getValue(byte[])}, {@link #getValue(byte[], int)},
 * {@link #getValueStream}.
 * 
 * @return the length of the value. Does not require
 *         isValueLengthKnown() to be true.
 * @throws IOException
 */
public int getValue(byte[] buf, int offset) throws IOException {
  DataInputStream dis = getValueStream();
  try {
    if (isValueLengthKnown()) {
      if ((offset | (buf.length - offset - vlen)) < 0) {
        throw new IndexOutOfBoundsException(
            "Buffer too small to hold value");
      }
      dis.readFully(buf, offset, vlen);
      return vlen;
    }

    int nextOffset = offset;
    while (nextOffset < buf.length) {
      int n = dis.read(buf, nextOffset, buf.length - nextOffset);
      if (n < 0) {
        break;
      }
      nextOffset += n;
    }
    if (dis.read() >= 0) {
      // attempt to read one more byte to determine whether we reached
      // the
      // end or not.
      throw new IndexOutOfBoundsException(
          "Buffer too small to hold value");
    }
    return nextOffset - offset;
  } finally {
    dis.close();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:46,代码来源:TFile.java

示例7: readFile

import java.io.DataInputStream; //导入方法依赖的package包/类
private void readFile(FileSystem fileSys, Path name) throws IOException {
  DataInputStream stm = fileSys.open(name);
  byte[] buffer = new byte[4];
  int bytesRead = stm.read(buffer, 0 , 4);
  assertEquals("oom", new String(buffer, 0 , bytesRead));
  stm.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:8,代码来源:TestLocalDFS.java

示例8: someReadingWithMetaBlock

import java.io.DataInputStream; //导入方法依赖的package包/类
private void someReadingWithMetaBlock(Reader reader) throws IOException {
  DataInputStream din = null;
  readNumMetablocks(reader, 10);
  try {
    din = reader.getMetaBlock("NO ONE");
    assertTrue(false);
  }
  catch (MetaBlockDoesNotExist me) {
    // should catch
  }
  din = reader.getMetaBlock("TFileMeta100");
  int read = din.read();
  assertTrue("check for status", (read == -1));
  din.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:16,代码来源:TestTFile.java

示例9: loadFileInfo

import java.io.DataInputStream; //导入方法依赖的package包/类
/**
 * Read in the index and file info.
 * @return A map of fileinfo data.
 * See {@link Writer#appendFileInfo(byte[], byte[])}.
 * @throws IOException
 */
public Map<byte [], byte []> loadFileInfo()
throws IOException {
  this.trailer = readTrailer();

  // Read in the fileinfo and get what we need from it.
  this.istream.seek(this.trailer.fileinfoOffset);
  FileInfo fi = new FileInfo();
  fi.readFields(this.istream);
  this.lastkey = fi.get(FileInfo.LASTKEY);
  this.avgKeyLen = Bytes.toInt(fi.get(FileInfo.AVG_KEY_LEN));
  this.avgValueLen = Bytes.toInt(fi.get(FileInfo.AVG_VALUE_LEN));
  String clazzName = Bytes.toString(fi.get(FileInfo.COMPARATOR));
  this.comparator = getComparator(clazzName);

  int allIndexSize = (int)(this.fileSize - this.trailer.dataIndexOffset - FixedFileTrailer.trailerSize());
  byte[] dataAndMetaIndex = readAllIndex(this.istream, this.trailer.dataIndexOffset, allIndexSize);

  ByteArrayInputStream bis = new ByteArrayInputStream(dataAndMetaIndex);
  DataInputStream dis = new DataInputStream(bis);

  // Read in the data index.
  this.blockIndex =
      BlockIndex.readIndex(this.comparator, dis, this.trailer.dataIndexCount);

  // Read in the metadata index.
  if (trailer.metaIndexCount > 0) {
    this.metaIndex = BlockIndex.readIndex(Bytes.BYTES_RAWCOMPARATOR, dis,
        this.trailer.metaIndexCount);
  }
  this.fileInfoLoaded = true;

  if (null != dis) {
    dis.close();
  }

  return fi;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:44,代码来源:IndexFile.java

示例10: readFile

import java.io.DataInputStream; //导入方法依赖的package包/类
public byte[] readFile(Path path, int len) throws IOException {
  DataInputStream dis = fs.open(path);
  byte[] buffer = new byte[len];
  IOUtils.readFully(dis, buffer, 0, len);
  dis.close();
  return buffer;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:8,代码来源:FileSystemTestWrapper.java

示例11: loadIdCounts

import java.io.DataInputStream; //导入方法依赖的package包/类
/**
 * Loads the idCounts Map from the 'idcounts' file.
 */
private void loadIdCounts()
{
    try
    {
        this.idCounts.clear();

        if (this.saveHandler == null)
        {
            return;
        }

        File file1 = this.saveHandler.getMapFileFromName("idcounts");

        if (file1 != null && file1.exists())
        {
            DataInputStream datainputstream = new DataInputStream(new FileInputStream(file1));
            NBTTagCompound nbttagcompound = CompressedStreamTools.read(datainputstream);
            datainputstream.close();

            for (String s : nbttagcompound.getKeySet())
            {
                NBTBase nbtbase = nbttagcompound.getTag(s);

                if (nbtbase instanceof NBTTagShort)
                {
                    NBTTagShort nbttagshort = (NBTTagShort)nbtbase;
                    short short1 = nbttagshort.getShort();
                    this.idCounts.put(s, Short.valueOf(short1));
                }
            }
        }
    }
    catch (Exception exception)
    {
        exception.printStackTrace();
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:41,代码来源:MapStorage.java

示例12: read

import java.io.DataInputStream; //导入方法依赖的package包/类
private static byte[] read(File file) {
    byte buff[] = new byte[(int)(file.length())];
    try {
        DataInputStream din = new DataInputStream(new FileInputStream(file));
        din.readFully(buff);
        din.close();
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    return buff;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:FragmentMetaspaceSimple.java

示例13: doRequest

import java.io.DataInputStream; //导入方法依赖的package包/类
boolean doRequest(BreventProtocol request) {
    boolean result = false;
    try (
            Socket socket = new Socket(InetAddress.getLoopbackAddress(), BreventProtocol.PORT)
    ) {
        socket.setSoTimeout(5000);

        DataOutputStream os = new DataOutputStream(socket.getOutputStream());
        BreventProtocol.writeTo(request, os);
        os.flush();

        DataInputStream is = new DataInputStream(socket.getInputStream());
        BreventProtocol response = BreventProtocol.readFrom(is);

        os.close();
        is.close();
        result = response == BreventOpsOK.INSTANCE;
        UILog.i("request: " + request + ", response: " + response);
    } catch (IOException e) {
        UILog.w("Can't request " + request, e);
    }
    if (!isStopped()) {
        final boolean update = result;
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (!isStopped()) {
                    hideProgress();
                    if (update) {
                        refresh();
                    } else {
                        ((BreventApplication) getApplication()).setGrantedWarned(false);
                        finish();
                    }
                }
            }
        });
    }
    return result;
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:41,代码来源:BreventOps.java

示例14: readFile

import java.io.DataInputStream; //导入方法依赖的package包/类
public byte[] readFile(Path path, int len) throws IOException {
  DataInputStream dis = fc.open(path);
  byte[] buffer = new byte[len];
  IOUtils.readFully(dis, buffer, 0, len);
  dis.close();
  return buffer;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:8,代码来源:FileContextTestWrapper.java

示例15: readFile

import java.io.DataInputStream; //导入方法依赖的package包/类
private void readFile(FileSystem fileSys,Path name) throws IOException {
  //Just read file so that getNumBlockLocations are incremented
  DataInputStream stm = fileSys.open(name);
  byte [] buffer = new byte[4];
  stm.read(buffer,0,4);
  stm.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:8,代码来源:TestNameNodeMetrics.java


注:本文中的java.io.DataInputStream.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。