Package java.io

Examples of java.io.DataInputStream$CacheLock


        }
        int len = dataInRaw.readInt();
        len -= 4;
        byte[] data = Utils.newBytes(len);
        dataInRaw.readFully(data, 0, len);
        dataIn = new DataInputStream(new ByteArrayInputStream(data, 0, len));
        switchBlock: switch (x) {
        case 0:
            server.trace("Init");
            int version = readInt();
            if (version == 80877102) {
View Full Code Here


                javacSun(javaFile);
            } else {
                javacProcess(javaFile);
            }
            byte[] data = new byte[(int) classFile.length()];
            DataInputStream in = new DataInputStream(new FileInputStream(classFile));
            in.readFully(data);
            in.close();
            return data;
        } catch (Exception e) {
            throw DbException.convert(e);
        } finally {
            javaFile.delete();
View Full Code Here

        if(!inChannel.isBlocking()) {
            inChannel.configureBlocking(true);
        }

        InputStream in = socket.getInputStream();
        DataInputStream dis = new DataInputStream(in);

        String fname = IOUtils.readString(dis);
        String dirPath = IOUtils.readString(dis);
        long len = dis.readLong();
        boolean append = dis.readBoolean();
        boolean ackRequired = dis.readBoolean();
        boolean hasAdditionalHeader = dis.readBoolean();
        if(hasAdditionalHeader) {
            readAdditionalHeader(dis, fname, dirPath, len, append, ackRequired);
        }

        final File file;
View Full Code Here

            IOUtils.closeQuietly(channel);
            NetUtils.closeQuietly(socket);
            throw e;
        }

        DataInputStream din = null;
        if(sync) {
            InputStream in = socket.getInputStream();
            din = new DataInputStream(in);
        }
        final DataOutputStream dos = new DataOutputStream(out);
        final StopWatch sw = new StopWatch();
        FileInputStream src = null;
        final long nbytes;
        try {
            src = new FileInputStream(file);
            FileChannel fc = src.getChannel();

            String fileName = file.getName();
            IOUtils.writeString(fileName, dos);
            IOUtils.writeString(writeDirPath, dos);
            long xferBytes = (count == -1L) ? fc.size() : count;
            dos.writeLong(xferBytes);
            dos.writeBoolean(append); // append=false
            dos.writeBoolean(sync);
            if(handler == null) {
                dos.writeBoolean(false);
            } else {
                dos.writeBoolean(true);
                handler.writeAdditionalHeader(dos);
            }

            // send file using zero-copy send
            nbytes = fc.transferTo(fromPos, xferBytes, channel);
            if(LOG.isDebugEnabled()) {
                LOG.debug("Sent a file '" + file.getAbsolutePath() + "' of " + nbytes
                        + " bytes to " + dstSockAddr.toString() + " in " + sw.toString());
            }

            if(sync) {// receive ack in sync mode
                long remoteRecieved = din.readLong();
                if(remoteRecieved != xferBytes) {
                    throw new IllegalStateException("Sent " + xferBytes
                            + " bytes, but remote node received " + remoteRecieved + " bytes");
                }
            }
View Full Code Here

            IOUtils.closeQuietly(channel);
            NetUtils.closeQuietly(socket);
            throw e;
        }

        DataInputStream din = null;
        if(sync) {
            InputStream in = socket.getInputStream();
            din = new DataInputStream(in);
        }
        final DataOutputStream dos = new DataOutputStream(out);
        final StopWatch sw = new StopWatch();
        try {
            IOUtils.writeString(fileName, dos);
            IOUtils.writeString(writeDirPath, dos);
            long nbytes = data.size();
            dos.writeLong(nbytes);
            dos.writeBoolean(append);
            dos.writeBoolean(sync);
            if(handler == null) {
                dos.writeBoolean(false);
            } else {
                dos.writeBoolean(true);
                handler.writeAdditionalHeader(dos);
            }

            // send file using zero-copy send
            data.writeTo(out);

            if(LOG.isDebugEnabled()) {
                LOG.debug("Sent a file data '" + fileName + "' of " + nbytes + " bytes to "
                        + dstSockAddr.toString() + " in " + sw.toString());
            }

            if(sync) {// receive ack in sync mode
                long remoteRecieved = din.readLong();
                if(remoteRecieved != nbytes) {
                    throw new IllegalStateException("Sent " + nbytes
                            + " bytes, but remote node received " + remoteRecieved + " bytes");
                }
            }
View Full Code Here

    }
  }

  Character loadCharacter (String name) {
    File file = new File("characters", name.toLowerCase());
    DataInputStream input = null;
    try {
      input = new DataInputStream(new FileInputStream(file));
      Character character = new Character();
      character.id = input.readInt();
      character.name = name;
      character.otherStuff = input.readUTF();
      character.x = input.readInt();
      character.y = input.readInt();
      input.close();
      return character;
    } catch (IOException ex) {
      ex.printStackTrace();
      return null;
    } finally {
      try {
        if (input != null) input.close();
      } catch (IOException ignored) {
      }
    }
  }
View Full Code Here

  public void testRemappedIndex( boolean interleaved, Map<Component, Coding> flags, int quantum, int height, TermProcessor termProcessor ) throws IOException, ConfigurationException, SecurityException, URISyntaxException, ClassNotFoundException,
      InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    final String basenameMapped = basename + "-map";
    int[] map = IntIterators.unwrap( BinIO.asIntIterator( new DataInputStream( this.getClass().getResourceAsStream( "documents.permutation.data" ) ) ) );
    String mapFile = File.createTempFile( this.getClass().getSimpleName(), "map" ).toString();
    BinIO.storeInts( map, mapFile );

    // Remapped index
    new IndexBuilder( basenameMapped, getSequence() ).standardWriterFlags( flags ).termProcessor( termProcessor ).skipBufferSize( 1024 ).pasteBufferSize( 1024 ).interleaved( interleaved ).skips( quantum != 0 ).quantum(
View Full Code Here

            File file = new File(filename);
            if (file.isFile()) {
                long length = file.length();
                if (length < Integer.MAX_VALUE) {
                    byte[] classbytes = new byte[(int)length];
                    DataInputStream in =
                        new DataInputStream(new FileInputStream(file));
                    in.readFully(classbytes);
                    in.close();
                    Class c = defineClass(null, classbytes, 0, (int) length);
                    if (c != null) {
                        resolveClass(c);
                        return c;
                    }
View Full Code Here

            final int tupleCount = ph.getTupleCount();
            if(tupleCount == 0) {
                return;
            }
            Value v = readValue(page);
            DataInputStream in = new DataInputStream(v.getInputStream());
            for(int i = 0; i < tupleCount; i++) {
                int len = in.readInt();
                byte[] tuple = new byte[len];
                in.read(tuple);
                tuples.add(tuple);
            }
            if(in.available() > 0) {
                throw new IllegalStateException(in.available() + " bytes left");
            }
            this.totalDataLen = v.getLength();
            this.loaded = true;
        }
View Full Code Here

         * Reads node only if it is not loaded yet
         */
        private void read() throws IOException, DbException {
            if(!this.loaded) {
                Value v = readValue(page);
                DataInputStream in = new DataInputStream(v.getInputStream());
                // Read in the common prefix (if any)
                final short pfxLen = ph.getPrefixLength();
                final byte[] pfxBytes;
                if(pfxLen > 0) {
                    pfxBytes = new byte[pfxLen];
                    in.read(pfxBytes);
                    this.prefix = new Value(pfxBytes);
                } else {
                    pfxBytes = EmptyBytes;
                    this.prefix = EmptyValue;
                }
                // Read in the Values
                Value prevKey = null;
                final int keyslen = ph.getValueCount();
                keys = new Value[keyslen];
                for(int i = 0; i < keyslen; i++) {
                    final int valSize = in.readInt();
                    if(valSize == -1) {
                        prevKey.incrRefCount();
                        keys[i] = prevKey;
                    } else {
                        byte[] b = new byte[pfxLen + valSize];
                        if(pfxLen > 0) {
                            System.arraycopy(pfxBytes, 0, b, 0, pfxLen);
                        }
                        if(valSize > 0) {
                            in.read(b, pfxLen, valSize);
                        }
                        prevKey = new Value(b);
                        keys[i] = prevKey;
                    }
                }
                // Read in the pointers
                final int ptrslen = ph.getPointerCount();
                ptrs = new long[ptrslen];
                for(int i = 0; i < ptrslen; i++) {
                    ptrs[i] = VariableByteCodec.decodeLong(in);
                }
                // Read in the links if current node is a leaf
                if(ph.getStatus() == LEAF) {
                    this._prev = in.readLong();
                    this._next = in.readLong();
                }
                this.currentDataLen = v.getLength();
                this.loaded = true;
            }
        }
View Full Code Here

TOP

Related Classes of java.io.DataInputStream$CacheLock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.