Java Code Examples for java.io.DataInputStream

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project blacktie, under directory /btadmin/src/main/java/org/jboss/narayana/blacktie/btadmin/.

Source file: CommandHandler.java

  33 
vote

private long convertLong(byte[] response) throws IOException {
  ByteArrayInputStream baos=new ByteArrayInputStream(response);
  DataInputStream dos=new DataInputStream(baos);
  ByteBuffer bbuf=ByteBuffer.allocate(BufferImpl.LONG_SIZE);
  bbuf.order(ByteOrder.BIG_ENDIAN);
  bbuf.put(response);
  bbuf.order(ByteOrder.LITTLE_ENDIAN);
  return bbuf.getLong(0);
}
 

Example 2

From project CBCJVM, under directory /cbc/CBCJVM/src/cbccore/display/.

Source file: Image.java

  33 
vote

public Image(File image) throws IOException {
  InputStream in=new FileInputStream(image);
  DataInputStream dIn=new DataInputStream(in);
  width=dIn.readInt();
  bytes=new int[dIn.available()];
  int i=0;
  while (dIn.available() > 0) {
    bytes[i]=dIn.readInt();
    ++i;
  }
}
 

Example 3

From project akela, under directory /src/main/java/com/mozilla/hadoop/hbase/mapreduce/.

Source file: MultiScanTableMapReduceUtil.java

  32 
vote

/** 
 * Converts base64 scans string back into a Scan array
 * @param base64
 * @return
 * @throws IOException
 */
public static Scan[] convertStringToScanArray(final String base64) throws IOException {
  final DataInputStream dis=new DataInputStream(new ByteArrayInputStream(Base64.decode(base64)));
  ArrayWritable aw=new ArrayWritable(Scan.class);
  aw.readFields(dis);
  Writable[] writables=aw.get();
  Scan[] scans=new Scan[writables.length];
  for (int i=0; i < writables.length; i++) {
    scans[i]=(Scan)writables[i];
  }
  return scans;
}
 

Example 4

From project AlbiteREADER, under directory /src/org/albite/image/.

Source file: AlbiteImageARGB.java

  32 
vote

public AlbiteImageARGB(final InputStream in) throws IOException, AlbiteImageException {
  final DataInputStream din=new DataInputStream(in);
  loadHeader(din);
  argbData=new int[width * height];
  for (int i=0; i < width * height; i++) {
    argbData[i]=din.readByte() << 24;
  }
  din.close();
}
 

Example 5

From project Application-Builder, under directory /src/main/java/org/silverpeas/helpbuilder/.

Source file: TemplateBasedBuilder.java

  32 
vote

private String getTemplate(String templateFileName) throws Exception {
  File templateFile=new File(getMyPropertiesPath(),templateFileName);
  long templateFileSize=templateFile.length();
  if (templateFileSize > Integer.MAX_VALUE) {
    throw new Exception("the template file " + templateFileName + " is too big for a string");
  }
  byte[] data=new byte[(int)templateFile.length()];
  DataInputStream in=new DataInputStream(new FileInputStream(templateFile));
  in.readFully(data);
  return new String(data);
}
 

Example 6

From project Arecibo, under directory /util/src/main/java/com/ning/arecibo/util/timeline/times/.

Source file: TimesAndSamplesCoder.java

  32 
vote

public static int getSizeOfTimeBytes(final byte[] timesAndSamples){
  final DataInputStream inputStream=new DataInputStream(new ByteArrayInputStream(timesAndSamples));
  try {
    return inputStream.readInt();
  }
 catch (  IOException e) {
    throw new IllegalStateException(String.format("Exception reading timeByteCount in TimelineChunkMapper.map() for timesAndSamples %s",Hex.encodeHex(timesAndSamples)),e);
  }
}
 

Example 7

From project ciel-java, under directory /examples/kmeans/src/java/skywriting/examples/kmeans/.

Source file: KMeansHead.java

  32 
vote

@Override public void invoke() throws Exception {
  DataInputStream dis=new DataInputStream(new FileInputStream(Ciel.RPC.getFilenameForReference(this.dataPartitionRef)));
  WritableReference out=Ciel.RPC.getOutputFilename(0);
  DataOutputStream dos=new DataOutputStream(out.open());
  for (int i=0; i < this.k * this.numDimensions; ++i) {
    dos.writeDouble(dis.readDouble());
  }
  dis.close();
  dos.close();
}
 

Example 8

From project Clotho-Core, under directory /ClothoApps/SeqAnalyzer/src/org/clothocad/algorithm/seqanalyzer/sequencing/.

Source file: ABITrace.java

  32 
vote

/** 
 * Fetch the basecalls from the trace data.
 */
private void setBasecalls(){
  Basecalls=new int[SeqLength];
  byte[] qq=new byte[SeqLength * 2];
  getSubArray(qq,PLOC);
  DataInputStream dis=new DataInputStream(new ByteArrayInputStream(qq));
  for (int i=0; i <= SeqLength - 1; ++i) {
    try {
      Basecalls[i]=(int)dis.readShort();
    }
 catch (    IOException e) {
      throw new IllegalStateException("Unexpected IOException encountered while manipulating internal streams.");
    }
  }
}
 

Example 9

From project Cloud9, under directory /src/dist/edu/umd/cloud9/collection/clue/.

Source file: ClueWarcInputFormat.java

  32 
vote

@Override public boolean next(LongWritable key,ClueWarcRecord value) throws IOException {
  DataInputStream whichStream=input;
  ClueWarcRecord newRecord=ClueWarcRecord.readNextWarcRecord(whichStream);
  if (newRecord == null) {
    return false;
  }
  totalNumBytesRead+=(long)newRecord.getTotalRecordLength();
  newRecord.setWarcFilePath(path.toString());
  value.set(newRecord);
  key.set(recordCount);
  recordCount++;
  return true;
}
 

Example 10

From project culvert, under directory /culvert-main/src/test/java/com/bah/culvert/test/.

Source file: Utils.java

  32 
vote

/** 
 * Checks if the writable will successfully read and write using {@link Writable}'s methods.
 * @param writeable
 * @return The instance read in using{@link Writable#readFields(java.io.DataInput)}. Can be used for checking equality.
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws IOException
 */
public static Writable testReadWrite(Writable writeable) throws InstantiationException, IllegalAccessException, IOException {
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  DataOutputStream dos=new DataOutputStream(baos);
  writeable.write(dos);
  ByteArrayInputStream bais=new ByteArrayInputStream(baos.toByteArray());
  DataInputStream dis=new DataInputStream(bais);
  Writable inst=writeable.getClass().newInstance();
  inst.readFields(dis);
  return inst;
}
 

Example 11

From project datasalt-utils, under directory /src/main/java/com/datasalt/utils/commons/.

Source file: WritableUtils.java

  32 
vote

/** 
 * Deserialize Writables
 */
public static Writable deserialize(Writable datum,byte[] bytes) throws IOException {
  ByteArrayInputStream bis=new ByteArrayInputStream(bytes);
  DataInputStream dis=new DataInputStream(bis);
  datum.readFields(dis);
  dis.close();
  return datum;
}
 

Example 12

From project des, under directory /daemon/lib/apache-log4j-1.2.16/tests/src/java/org/apache/log4j/varia/.

Source file: ERFATestCase.java

  32 
vote

/** 
 * Send a message to the ERFA.
 * @param port port number.
 * @param msg message, may not be null.
 * @param expectedResponse expected response, may not be null.
 * @throws IOException thrown on IO error.
 */
void sendMessage(int port,final String msg,final String expectedResponse) throws IOException {
  Socket socket=new Socket((String)null,port);
  DataInputStream reader=new DataInputStream(socket.getInputStream());
  DataOutputStream writer=new DataOutputStream(socket.getOutputStream());
  writer.writeUTF(msg);
  String response=reader.readUTF();
  assertEquals(expectedResponse,response);
  reader.close();
  writer.close();
  socket.close();
}
 

Example 13

From project DeskSMS, under directory /DeskSMS/src/com/koushikdutta/desktopsms/.

Source file: StreamUtility.java

  32 
vote

public static byte[] readToEndAsArray(InputStream input) throws IOException {
  DataInputStream dis=new DataInputStream(input);
  byte[] stuff=new byte[1024];
  ByteArrayOutputStream buff=new ByteArrayOutputStream();
  int read=0;
  while ((read=dis.read(stuff)) != -1) {
    buff.write(stuff,0,read);
  }
  input.close();
  return buff.toByteArray();
}
 

Example 14

From project dragon, under directory /hadoop-dragon-core/src/main/java/org/apache/hadoop/realtime/security/token/delegation/.

Source file: DelegationTokenIdentifier.java

  32 
vote

/** 
 * @return a string representation of the token 
 */
public static String stringifyToken(final Token<?> token) throws IOException {
  DelegationTokenIdentifier ident=new DelegationTokenIdentifier();
  ByteArrayInputStream buf=new ByteArrayInputStream(token.getIdentifier());
  DataInputStream in=new DataInputStream(buf);
  ident.readFields(in);
  if (token.getService().getLength() > 0) {
    return ident + " on " + token.getService();
  }
 else {
    return ident.toString();
  }
}
 

Example 15

From project 3Dto2DApplet, under directory /src/java/nl/dannyarends/eventHandling/.

Source file: NetworkHandler.java

  31 
vote

public NetworkHandler(String host,int port){
  commandStack=new ClientCommands(this);
  try {
    s=new Socket(host,port);
    is=new DataInputStream(s.getInputStream());
    os=new DataOutputStream(s.getOutputStream());
  }
 catch (  Exception e) {
    System.err.println("No connection");
    e.printStackTrace();
    connected=false;
  }
}
 

Example 16

From project accent, under directory /src/test/java/net/lshift/accent/.

Source file: ControlledConnectionProxy.java

  31 
vote

public void run(){
  try {
    this.inServer=new ServerSocket(listenPort);
    inServer.setReuseAddress(true);
    this.inSock=inServer.accept();
    this.outSock=new Socket(host,port);
    DataInputStream iis=new DataInputStream(this.inSock.getInputStream());
    DataOutputStream ios=new DataOutputStream(this.inSock.getOutputStream());
    DataInputStream ois=new DataInputStream(this.outSock.getInputStream());
    DataOutputStream oos=new DataOutputStream(this.outSock.getOutputStream());
    byte[] handshake=new byte[8];
    iis.readFully(handshake);
    oos.write(handshake);
    BlockingCell<Exception> wio=new BlockingCell<Exception>();
    new Thread(new DirectionHandler(wio,true,iis,oos)).start();
    new Thread(new DirectionHandler(wio,false,ois,ios)).start();
    waitAndLogException(wio);
  }
 catch (  Exception e) {
    reportAndLogNonNullException(e);
  }
 finally {
    try {
      if (this.inSock != null)       this.inSock.close();
    }
 catch (    Exception e) {
      logException(e);
    }
    try {
      if (this.outSock != null)       this.outSock.close();
    }
 catch (    Exception e) {
      logException(e);
    }
    this.reportEnd.setIfUnset(null);
  }
}
 

Example 17

From project activemq-apollo, under directory /apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/.

Source file: ActiveMQObjectMessage.java

  31 
vote

/** 
 * Gets the serializable object containing this message's data. The default value is null.
 * @return the serializable object containing this message's data
 * @throws OpenwireException
 */
public Serializable getObject() throws OpenwireException {
  if (object == null && getContent() != null) {
    try {
      Buffer content=getContent();
      InputStream is=new ByteArrayInputStream(content);
      if (isCompressed()) {
        is=new InflaterInputStream(is);
      }
      DataInputStream dataIn=new DataInputStream(is);
      ClassLoadingAwareObjectInputStream objIn=new ClassLoadingAwareObjectInputStream(dataIn);
      try {
        object=(Serializable)objIn.readObject();
      }
 catch (      ClassNotFoundException ce) {
        throw new OpenwireException("Failed to build body from content. Serializable class not available to broker. Reason: " + ce,ce);
      }
 finally {
        dataIn.close();
      }
    }
 catch (    IOException e) {
      throw new OpenwireException("Failed to build body from bytes. Reason: " + e,e);
    }
  }
  return this.object;
}
 

Example 18

From project aim3-tu-berlin, under directory /seminar/exercises/datamining/core/src/test/java/de/tuberlin/dima/aim/exercises/one/.

Source file: PrimeNumbersWritableTest.java

  31 
vote

@Test public void writeAndRead() throws IOException {
  PrimeNumbersWritable original=new PrimeNumbersWritable(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97);
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  original.write(new DataOutputStream(out));
  PrimeNumbersWritable clone=new PrimeNumbersWritable();
  clone.readFields(new DataInputStream(new ByteArrayInputStream(out.toByteArray())));
  assertEquals(original,clone);
}
 

Example 19

From project Alerte-voirie-android, under directory /src/com/fabernovel/alertevoirie/data/.

Source file: CategoryProvider.java

  31 
vote

@Override public boolean onCreate(){
  DataInputStream in=new DataInputStream(getContext().getResources().openRawResource(R.raw.categories));
  try {
    byte[] buffer=new byte[in.available()];
    in.read(buffer);
    categories=(JSONObject)new JSONTokener(new String(buffer)).nextValue();
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
catch (  JSONException e) {
    Log.e("Alerte Voirie","JSON error",e);
  }
  return true;
}
 

Example 20

From project android_build, under directory /tools/signapk/.

Source file: SignApk.java

  31 
vote

/** 
 * Read a PKCS 8 format private key. 
 */
private static PrivateKey readPrivateKey(File file) throws IOException, GeneralSecurityException {
  DataInputStream input=new DataInputStream(new FileInputStream(file));
  try {
    byte[] bytes=new byte[(int)file.length()];
    input.read(bytes);
    KeySpec spec=decryptPrivateKey(bytes,file);
    if (spec == null) {
      spec=new PKCS8EncodedKeySpec(bytes);
    }
    try {
      return KeyFactory.getInstance("RSA").generatePrivate(spec);
    }
 catch (    InvalidKeySpecException ex) {
      return KeyFactory.getInstance("DSA").generatePrivate(spec);
    }
  }
  finally {
    input.close();
  }
}
 

Example 21

From project android_packages_apps_Gallery, under directory /src/com/android/camera/.

Source file: ThumbnailController.java

  31 
vote

public boolean loadData(String filePath){
  FileInputStream f=null;
  BufferedInputStream b=null;
  DataInputStream d=null;
  try {
    f=new FileInputStream(filePath);
    b=new BufferedInputStream(f,BUFSIZE);
    d=new DataInputStream(b);
    Uri uri=Uri.parse(d.readUTF());
    Bitmap thumb=BitmapFactory.decodeStream(d);
    setData(uri,thumb);
    d.close();
  }
 catch (  IOException e) {
    return false;
  }
 finally {
    MenuHelper.closeSilently(f);
    MenuHelper.closeSilently(b);
    MenuHelper.closeSilently(d);
  }
  return true;
}
 

Example 22

From project android_packages_apps_Gallery2, under directory /src/com/android/gallery3d/app/.

Source file: MoviePlayer.java

  31 
vote

public Integer getBookmark(Uri uri){
  try {
    BlobCache cache=CacheManager.getCache(mContext,BOOKMARK_CACHE_FILE,BOOKMARK_CACHE_MAX_ENTRIES,BOOKMARK_CACHE_MAX_BYTES,BOOKMARK_CACHE_VERSION);
    byte[] data=cache.lookup(uri.hashCode());
    if (data == null)     return null;
    DataInputStream dis=new DataInputStream(new ByteArrayInputStream(data));
    String uriString=dis.readUTF(dis);
    int bookmark=dis.readInt();
    int duration=dis.readInt();
    if (!uriString.equals(uri.toString())) {
      return null;
    }
    if ((bookmark < HALF_MINUTE) || (duration < TWO_MINUTES) || (bookmark > (duration - HALF_MINUTE))) {
      return null;
    }
    return Integer.valueOf(bookmark);
  }
 catch (  Throwable t) {
    Log.w(TAG,"getBookmark failed",t);
  }
  return null;
}
 

Example 23

From project android_packages_apps_Gallery3D, under directory /src/com/cooliris/cache/.

Source file: CacheService.java

  31 
vote

public static final void loadMediaSet(final Context context,final MediaFeed feed,final DataSource source,final long bucketId){
  syncCache(context);
  final byte[] albumData=sAlbumCache.get(ALBUM_CACHE_METADATA_INDEX,0);
  if (albumData != null && albumData.length > 0) {
    DataInputStream dis=new DataInputStream(new BufferedInputStream(new ByteArrayInputStream(albumData),256));
    try {
      final int numAlbums=dis.readInt();
      for (int i=0; i < numAlbums; ++i) {
        final long setId=dis.readLong();
        MediaSet mediaSet=null;
        if (setId == bucketId) {
          mediaSet=feed.getMediaSet(setId);
          if (mediaSet == null) {
            mediaSet=feed.addMediaSet(setId,source);
          }
        }
 else {
          mediaSet=new MediaSet();
        }
        mediaSet.mName=Utils.readUTF(dis);
        if (setId == bucketId) {
          mediaSet.mPicasaAlbumId=Shared.INVALID;
          mediaSet.generateTitle(true);
          return;
        }
      }
    }
 catch (    IOException e) {
      Log.e(TAG,"Error finding album " + bucketId);
      sAlbumCache.deleteAll();
      putLocaleForAlbumCache(Locale.getDefault());
    }
  }
 else {
    if (DEBUG)     Log.d(TAG,"No album found for album id " + bucketId);
  }
}
 

Example 24

From project android_packages_apps_Superuser, under directory /src/com/noshufou/android/su/.

Source file: SuRequestActivity.java

  31 
vote

private void readRequestDetails(int suVersion,Intent intent) throws IOException {
  if (suVersion > 15) {
    mFromSocket=true;
    DataInputStream is=new DataInputStream(mSocket.getInputStream());
    int protocolVersion=is.readInt();
    Log.d(TAG,"INT32:PROTO VERSION = " + protocolVersion);
    int exeSizeMax=is.readInt();
    Log.d(TAG,"UINT32:FIELD7MAX = " + exeSizeMax);
    int cmdSizeMax=is.readInt();
    Log.d(TAG,"UINT32:FIELD9MAX = " + cmdSizeMax);
    mCallerUid=is.readInt();
    Log.d(TAG,"UINT32:CALLER = " + mCallerUid);
    mDesiredUid=is.readInt();
    Log.d(TAG,"UINT32:TO = " + mDesiredUid);
    int exeSize=is.readInt();
    Log.d(TAG,"UINT32:EXESIZE = " + exeSize);
    if (exeSize > exeSizeMax) {
      throw new IOException("Incomming string bigger than allowed");
    }
    byte[] buf=new byte[exeSize];
    is.read(buf);
    String callerBin=new String(buf,0,exeSize - 1);
    Log.d(TAG,"STRING:EXE = " + callerBin);
    int cmdSize=is.readInt();
    Log.d(TAG,"UINT32:CMDSIZE = " + cmdSize);
    if (cmdSize > cmdSizeMax) {
      throw new IOException("Incomming string bigger than allowed");
    }
    buf=new byte[cmdSize];
    is.read(buf);
    mDesiredCmd=new String(buf,0,cmdSize - 1);
    Log.d(TAG,"STRING:CMD = " + mDesiredCmd);
  }
 else {
    mFromSocket=false;
    mCallerUid=intent.getIntExtra(SuRequestReceiver.EXTRA_CALLERUID,0);
    mDesiredUid=intent.getIntExtra(SuRequestReceiver.EXTRA_UID,0);
    mDesiredCmd=intent.getStringExtra(SuRequestReceiver.EXTRA_CMD);
  }
}
 

Example 25

From project ant4eclipse, under directory /org.ant4eclipse.ant.jdt/src/org/ant4eclipse/ant/jdt/ecj/.

Source file: A4ECompilerAdapter.java

  31 
vote

/** 
 * <p> </p>
 * @param sourceFile
 * @param lineNumber
 * @param sourceStart
 * @param sourceEnd
 * @return
 */
private String[] readProblematicLine(SourceFile sourceFile,CategorizedProblem categorizedProblem){
  Assure.notNull("sourceFile",sourceFile);
  Assure.notNull("categorizedProblem",categorizedProblem);
  int lineNumber=categorizedProblem.getSourceLineNumber();
  int sourceStart=categorizedProblem.getSourceStart();
  int sourceEnd=categorizedProblem.getSourceEnd();
  try {
    FileInputStream fstream=new FileInputStream(sourceFile.getSourceFile());
    DataInputStream in=new DataInputStream(fstream);
    BufferedReader br=new BufferedReader(new InputStreamReader(in));
    int lineStart=0;
    String strLine="";
    for (int i=0; i < lineNumber; i++) {
      String newLine=br.readLine();
      lineStart=lineStart + strLine.length();
      if (i + 1 != lineNumber) {
        lineStart=lineStart + 1;
      }
      strLine=newLine;
    }
    Utilities.close(in);
    StringBuilder underscoreLine=new StringBuilder();
    for (int i=lineStart; i < sourceStart; i++) {
      if (strLine.charAt(i - lineStart) == '\t') {
        underscoreLine.append('\t');
      }
 else {
        underscoreLine.append(' ');
      }
    }
    for (int i=sourceStart; i <= sourceEnd; i++) {
      underscoreLine.append('^');
    }
    return new String[]{strLine,underscoreLine.toString()};
  }
 catch (  Exception e) {
    return new String[]{"",""};
  }
}
 

Example 26

From project apps-for-android, under directory /AndroidGlobalTime/src/com/android/globaltime/.

Source file: City.java

  31 
vote

/** 
 * Loads the city database.  The cities must be stored in order by raw offset from UTC.
 */
public static void loadCities(InputStream is) throws IOException {
  DataInputStream dis=new DataInputStream(is);
  int numCities=dis.readInt();
  citiesByRawOffset=new City[numCities];
  byte[] buf=new byte[24];
  for (int i=0; i < numCities; i++) {
    String name=dis.readUTF();
    String tzid=dis.readUTF();
    dis.read(buf);
    int rawOffset=(buf[0] << 24) | ((buf[1] & 0xff) << 16) | ((buf[2] & 0xff) << 8)| (buf[3] & 0xff);
    int ilat=(buf[4] << 24) | ((buf[5] & 0xff) << 16) | ((buf[6] & 0xff) << 8)| (buf[7] & 0xff);
    int ilon=(buf[8] << 24) | ((buf[9] & 0xff) << 16) | ((buf[10] & 0xff) << 8)| (buf[11] & 0xff);
    int icx=(buf[12] << 24) | ((buf[13] & 0xff) << 16) | ((buf[14] & 0xff) << 8)| (buf[15] & 0xff);
    int icy=(buf[16] << 24) | ((buf[17] & 0xff) << 16) | ((buf[18] & 0xff) << 8)| (buf[19] & 0xff);
    int icz=(buf[20] << 24) | ((buf[21] & 0xff) << 16) | ((buf[22] & 0xff) << 8)| (buf[23] & 0xff);
    float latitude=Float.intBitsToFloat(ilat);
    float longitude=Float.intBitsToFloat(ilon);
    float cx=Float.intBitsToFloat(icx);
    float cy=Float.intBitsToFloat(icy);
    float cz=Float.intBitsToFloat(icz);
    City city=new City(name,tzid,rawOffset,latitude,longitude,cx,cy,cz);
    cities.put(name,city);
    citiesByRawOffset[i]=city;
  }
}
 

Example 27

From project archive-commons, under directory /archive-commons/src/test/java/org/archive/util/.

Source file: ByteOpTest.java

  31 
vote

public void testReadShort() throws IOException {
  byte a[]=new byte[]{0,1,2,3};
  ByteArrayInputStream bais=new ByteArrayInputStream(a);
  int bos=ByteOp.readShort(bais);
  System.out.format("BO.Read short(%d)\n",bos);
  DataInputStream dis=new DataInputStream(new ByteArrayInputStream(a));
  int disv=dis.readUnsignedShort();
  System.out.format("DI.Read short(%d)\n",disv);
  for (int i=0; i < 256 * 256; i++) {
    ByteArrayOutputStream baos=new ByteArrayOutputStream(2);
    LittleEndianDataOutputStream dos=new LittleEndianDataOutputStream(baos);
    dos.writeShort(i);
    ByteArrayInputStream bais2=new ByteArrayInputStream(baos.toByteArray());
    int gotI=ByteOp.readShort(bais2);
    assertEquals(i,gotI);
  }
}
 

Example 28

From project ardverk-commons, under directory /src/main/java/org/ardverk/security/.

Source file: SecurityUtils.java

  31 
vote

/** 
 * Creates and returns a  {@link SecureRandom}. The difference between this factory method and  {@link SecureRandom}'s default constructor is that this will try to initialize the  {@link SecureRandom} withan initial seed from /dev/urandom while the default constructor will attempt to do the same from /dev/random which may block if there is not enough data available.
 */
public static SecureRandom createSecureRandom(){
  File file=new File("/dev/urandom");
  if (file.exists() && file.canRead()) {
    try (DataInputStream in=new DataInputStream(new FileInputStream(file))){
      byte[] seed=new byte[SEED_LENGTH];
      in.readFully(seed);
      return new SecureRandom(seed);
    }
 catch (    SecurityException|IOException ignore) {
    }
  }
  return new SecureRandom();
}
 

Example 29

From project artimate, under directory /artimate-demo/src/main/java/com/jdotsoft/jarloader/.

Source file: JarClassLoader.java

  31 
vote

/** 
 * Read JAR entry and returns byte array of this JAR entry. This is a helper method to load JAR entry into temporary file.
 * @param inf JAR entry information object
 * @return byte array for the specified JAR entry
 * @throws JarClassLoaderException
 */
byte[] getJarBytes() throws JarClassLoaderException {
  DataInputStream dis=null;
  byte[] a_by=null;
  try {
    long lSize=jarEntry.getSize();
    if (lSize <= 0 || lSize >= Integer.MAX_VALUE) {
      throw new JarClassLoaderException("Invalid size " + lSize + " for entry "+ jarEntry);
    }
    a_by=new byte[(int)lSize];
    InputStream is=jarFileInfo.jarFile.getInputStream(jarEntry);
    dis=new DataInputStream(is);
    dis.readFully(a_by);
  }
 catch (  IOException e) {
    throw new JarClassLoaderException(null,e);
  }
 finally {
    if (dis != null) {
      try {
        dis.close();
      }
 catch (      IOException e) {
      }
    }
  }
  return a_by;
}
 

Example 30

From project bdb-index, under directory /src/main/java/org/neo4j/index/bdbje/.

Source file: BerkeleyDbBatchInserterIndex.java

  31 
vote

@Override public IndexHits<Long> get(String key,Object value){
  ArrayList<Long> resultList=new ArrayList<Long>();
  Database db=dbs.get(key);
  if (null == db) {
    return new IndexHitsImpl<Long>(resultList,0);
  }
  DatabaseEntry result=new DatabaseEntry();
  try {
    OperationStatus status=db.get(null,new DatabaseEntry(value.toString().getBytes("UTF-8")),result,LockMode.READ_UNCOMMITTED);
    if (status == OperationStatus.NOTFOUND) {
      return new IndexHitsImpl<Long>(resultList,0);
    }
    byte[] data=result.getData();
    if (null == data) {
      return new IndexHitsImpl<Long>(resultList,0);
    }
    DataInputStream dis=new DataInputStream(new ByteArrayInputStream(data));
    resultList.add(dis.readLong());
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  return new IndexHitsImpl<Long>(resultList,resultList.size());
}
 

Example 31

From project behemoth, under directory /io/src/main/java/com/digitalpebble/behemoth/io/warc/.

Source file: WarcFileRecordReader.java

  31 
vote

public boolean next(LongWritable key,WritableWarcRecord value) throws IOException {
  DataInputStream whichStream=null;
  if (compressionInput != null) {
    whichStream=compressionInput;
  }
 else   if (currentFile != null) {
    whichStream=currentFile;
  }
  if (whichStream == null) {
    return false;
  }
  WarcRecord newRecord=WarcRecord.readNextWarcRecord(whichStream);
  if (newRecord == null) {
    if (openNextFile()) {
      newRecord=WarcRecord.readNextWarcRecord(whichStream);
    }
    if (newRecord == null) {
      return false;
    }
  }
  totalNumBytesRead+=(long)newRecord.getTotalRecordLength();
  newRecord.setWarcFilePath(filePathList[currentFilePath].toString());
  value.setRecord(newRecord);
  key.set(recordNumber);
  recordNumber++;
  return true;
}
 

Example 32

From project BioMAV, under directory /ParrotControl/JavaDroneControl/src/com/codeminders/ardrone/video/.

Source file: uint.java

  31 
vote

public uint(byte[] bp,int start){
  try {
    byte[] b=new byte[4];
    b[0]=bp[start + 3];
    b[1]=bp[start + 2];
    b[2]=bp[start + 1];
    b[3]=bp[start + 0];
    ByteArrayInputStream bas=new ByteArrayInputStream(b);
    DataInputStream din=new DataInputStream(bas);
    this.base2=din.readInt();
  }
 catch (  Exception e) {
    throw new RuntimeException("error creating uint",e);
  }
}
 

Example 33

From project bundlemaker, under directory /main/org.bundlemaker.core/src/org/bundlemaker/core/util/.

Source file: ListUtils.java

  31 
vote

/** 
 * <p> </p>
 * @param file
 * @return
 * @throws FileNotFoundException
 */
public static Set<String> getFrom(File file) throws FileNotFoundException {
  Set<String> result=new HashSet<String>();
  try {
    FileInputStream fstream=new FileInputStream(file);
    DataInputStream in=new DataInputStream(fstream);
    BufferedReader br=new BufferedReader(new InputStreamReader(in));
    String strLine;
    while ((strLine=br.readLine()) != null) {
      result.add(strLine);
    }
    in.close();
  }
 catch (  Exception e) {
    System.err.println("Error: " + e.getMessage());
  }
  return result;
}
 

Example 34

From project C-Cat, under directory /util/src/main/java/gov/llnl/ontology/util/.

Source file: StreamUtil.java

  31 
vote

/** 
 * Returns a  {@link DataInputStream} for reading object data from a gzipped{@link InputStream}.
 * @param in An existing {@link InputStream} whose data is in the gzippedformat
 * @return A {@link DataInputStream} for reading data from the gzippedstream
 */
public static DataInputStream gzipInputStream(InputStream in){
  try {
    return new DataInputStream(new GZIPInputStream(in));
  }
 catch (  IOException ioe) {
    throw new IOError(ioe);
  }
}
 

Example 35

From project Catroid-maven-playground, under directory /src/main/java/at/tugraz/ist/catroid/web/.

Source file: ConnectionWrapper.java

  31 
vote

public void doHttpPostFileDownload(String urlString,HashMap<String,String> postValues,String filePath) throws IOException {
  MultiPartFormOutputStream out=buildPost(urlString,postValues);
  out.close();
  DataInputStream input=new DataInputStream(urlConnection.getInputStream());
  File file=new File(filePath);
  file.getParentFile().mkdirs();
  FileOutputStream fos=new FileOutputStream(file);
  byte[] buffer=new byte[Constants.BUFFER_8K];
  int length=0;
  while ((length=input.read(buffer)) != -1) {
    fos.write(buffer,0,length);
  }
  input.close();
  fos.flush();
  fos.close();
}
 

Example 36

From project chukwa, under directory /src/test/java/org/apache/hadoop/chukwa/validationframework/util/.

Source file: DataOperations.java

  31 
vote

public static void extractRawLogFromDump(String directory,String fileName) throws Exception {
  File inputFile=new File(directory + fileName + ".bin");
  File outputFile=new File(directory + fileName + ".raw");
  DataInputStream dis=new DataInputStream(new FileInputStream(inputFile));
  Chunk chunk=null;
  FileWriter out=new FileWriter(outputFile);
  boolean eof=false;
  do {
    try {
      chunk=ChunkImpl.read(dis);
      out.write(new String(chunk.getData()));
    }
 catch (    EOFException e) {
      eof=true;
    }
  }
 while (!eof);
  dis.close();
  out.close();
}
 

Example 37

From project connectbot, under directory /src/net/sourceforge/jsocks/.

Source file: Socks4Message.java

  31 
vote

@Override public void read(InputStream in,boolean clientMode) throws IOException {
  boolean mode4a=false;
  DataInputStream d_in=new DataInputStream(in);
  version=d_in.readUnsignedByte();
  command=d_in.readUnsignedByte();
  if (clientMode && command != REPLY_OK) {
    String errMsg;
    if (command > REPLY_OK && command < REPLY_BAD_IDENTD)     errMsg=replyMessage[command - REPLY_OK];
 else     errMsg="Unknown Reply Code";
    throw new SocksException(command,errMsg);
  }
  port=d_in.readUnsignedShort();
  byte[] addr=new byte[4];
  d_in.readFully(addr);
  if (addr[0] == 0 && addr[1] == 0 && addr[2] == 0 && addr[3] != 0)   mode4a=true;
 else {
    ip=bytes2IP(addr);
    host=ip.getHostName();
  }
  if (!clientMode) {
    StringBuilder sb=new StringBuilder();
    int b;
    while ((b=in.read()) != 0)     sb.append((char)b);
    user=sb.toString();
    if (mode4a) {
      sb.setLength(0);
      while ((b=in.read()) != 0)       sb.append((char)b);
      host=sb.toString();
    }
  }
}
 

Example 38

From project core_4, under directory /impl/src/main/java/org/richfaces/util/.

Source file: Util.java

  31 
vote

public static void restoreResourceState(FacesContext context,Object resource,Object state){
  if (state == null) {
    return;
  }
  if (resource instanceof StateHolderResource) {
    StateHolderResource stateHolderResource=(StateHolderResource)resource;
    ByteArrayInputStream bais=new ByteArrayInputStream((byte[])state);
    DataInputStream dis=new DataInputStream(bais);
    try {
      stateHolderResource.readState(context,dis);
    }
 catch (    IOException e) {
      throw new FacesException(e.getMessage(),e);
    }
 finally {
      try {
        dis.close();
      }
 catch (      IOException e) {
        RESOURCE_LOGGER.debug(e.getMessage(),e);
      }
    }
  }
 else   if (resource instanceof StateHolder) {
    StateHolder stateHolder=(StateHolder)resource;
    stateHolder.restoreState(context,state);
  }
}
 

Example 39

From project cornerstone, under directory /frameworks/base/services/java/com/android/server/am/.

Source file: ActivityManagerService.java

  31 
vote

private static ArrayList<ComponentName> readLastDonePreBootReceivers(){
  ArrayList<ComponentName> lastDoneReceivers=new ArrayList<ComponentName>();
  File file=getCalledPreBootReceiversFile();
  FileInputStream fis=null;
  try {
    fis=new FileInputStream(file);
    DataInputStream dis=new DataInputStream(new BufferedInputStream(fis,2048));
    int fvers=dis.readInt();
    if (fvers == LAST_DONE_VERSION) {
      String vers=dis.readUTF();
      String codename=dis.readUTF();
      String build=dis.readUTF();
      if (android.os.Build.VERSION.RELEASE.equals(vers) && android.os.Build.VERSION.CODENAME.equals(codename) && android.os.Build.VERSION.INCREMENTAL.equals(build)) {
        int num=dis.readInt();
        while (num > 0) {
          num--;
          String pkg=dis.readUTF();
          String cls=dis.readUTF();
          lastDoneReceivers.add(new ComponentName(pkg,cls));
        }
      }
    }
  }
 catch (  FileNotFoundException e) {
  }
catch (  IOException e) {
    Slog.w(TAG,"Failure reading last done pre-boot receivers",e);
  }
 finally {
    if (fis != null) {
      try {
        fis.close();
      }
 catch (      IOException e) {
      }
    }
  }
  return lastDoneReceivers;
}
 

Example 40

From project Cours-3eme-ann-e, under directory /Java/FerryInpres/src/company_server/.

Source file: MobileCompanyServer.java

  31 
vote

@Override public void run(){
  try {
    DataInputStream in=new DataInputStream(this._sock.getInputStream());
    DataOutputStream out=new DataOutputStream(this._sock.getOutputStream());
    String numeroCarte=in.readUTF();
    if (this._data.utilisateurAuthorise(numeroCarte)) {
      out.writeChar('A');
      out.flush();
      System.out.println("Agent identifi?: " + numeroCarte);
      this.manageClient(in,out);
    }
 else {
      out.writeChar('F');
      out.flush();
      System.out.println("Echec d'authentification agent : " + numeroCarte);
    }
    this._sock.close();
  }
 catch (  Exception ex) {
    Logger.getLogger(MobileServerThread.class.getName()).log(Level.SEVERE,null,ex);
  }
}
 

Example 41

From project craftbook, under directory /circuits/src/main/java/com/sk89q/craftbook/plc/.

Source file: PlcIC.java

  31 
vote

private void loadState() throws IOException {
  if (!getStorageLocation().exists())   return;
  DataInputStream in=new DataInputStream(new FileInputStream(getStorageLocation()));
  try {
switch (in.readInt()) {
case 1:
      error=in.readBoolean();
    errorString=in.readUTF();
case 0:
  String langName=in.readUTF();
String id=in.readUTF();
String code=hashCode(in.readUTF());
if ((lang.getName().equals(langName) || lang.supports(langName)) && (isShared() || (id.equals(getID()) && hashCode(codeString).equals(code)))) {
lang.loadState(state,in);
}
 else {
error=false;
errorString="no error";
}
break;
default :
throw new IOException("incompatible version");
}
}
  finally {
in.close();
}
}
 

Example 42

From project CraftMania, under directory /CraftMania/src/org/craftmania/world/characters/.

Source file: Player.java

  31 
vote

public boolean load() throws IOException {
  File file=Game.getInstance().getRelativeFile(Game.FILE_BASE_USER_DATA,"${world}/player.dat");
  if (!file.exists()) {
    return false;
  }
  DataInputStream dis=new DataInputStream(new FileInputStream(file));
  IOUtilities.readVec3f(dis,getPosition());
  x=getPosition().x();
  y=getPosition().y();
  z=getPosition().z();
  _rotationSegment=dis.readInt();
  rotY=_rotationSegment / 10.0f * MathHelper.f_PI;
  IOUtilities.readVec3f(dis,getSpawnPoint());
  InventoryIO.readInventory(dis,getInventory(),0);
  _selectedInventoryItemIndex=dis.readByte();
  setSelectedInventoryItemIndex(_selectedInventoryItemIndex);
  dis.close();
  return true;
}
 

Example 43

From project crammer, under directory /src/main/java/uk/ac/ebi/ena/sra/cram/impl/.

Source file: CramIterator.java

  31 
vote

public CramIterator(InputStream is,ReferenceSequenceFile referenceSequenceFile,CramHeader header) throws IOException, CramFormatException {
  if (!Utils.isCRAM(is))   throw new RuntimeException("Not a valid CRAM format.");
  if (is instanceof DataInputStream)   this.is=(DataInputStream)is;
 else   this.is=new DataInputStream(is);
  this.referenceSequenceFile=referenceSequenceFile;
  if (header == null)   readHeader();
}
 

Example 44

From project crunch, under directory /crunch/src/main/java/org/apache/crunch/types/avro/.

Source file: Avros.java

  31 
vote

@Override public T map(ByteBuffer input){
  T instance=ReflectionUtils.newInstance(writableClazz,getConfiguration());
  try {
    instance.readFields(new DataInputStream(new ByteArrayInputStream(input.array(),input.arrayOffset(),input.limit())));
  }
 catch (  IOException e) {
    LOG.error("Exception thrown reading instance of: " + writableClazz,e);
  }
  return instance;
}
 

Example 45

From project curator, under directory /curator-recipes/src/main/java/com/netflix/curator/framework/recipes/queue/.

Source file: ItemSerializer.java

  31 
vote

static <T>MultiItem<T> deserialize(byte[] bytes,QueueSerializer<T> serializer) throws Exception {
  DataInputStream in=new DataInputStream(new ByteArrayInputStream(bytes));
  int version=in.readInt();
  if (version != VERSION) {
    throw new IOException(String.format("Incorrect version. Expected %d - Found: %d",VERSION,version));
  }
  List<T> items=Lists.newArrayList();
  for (; ; ) {
    byte opcode=in.readByte();
    if (opcode == EOF_OPCODE) {
      break;
    }
    if (opcode != ITEM_OPCODE) {
      throw new IOException(String.format("Incorrect opcode. Expected %d - Found: %d",ITEM_OPCODE,opcode));
    }
    int size=in.readInt();
    if (size < 0) {
      throw new IOException(String.format("Bad size: %d",size));
    }
    byte[] itemBytes=new byte[size];
    if (size > 0) {
      in.readFully(itemBytes);
    }
    items.add(serializer.deserialize(itemBytes));
  }
  final Iterator<T> iterator=items.iterator();
  return new MultiItem<T>(){
    @Override public T nextItem(){
      return iterator.hasNext() ? iterator.next() : null;
    }
  }
;
}
 

Example 46

From project daily-money, under directory /dailymoney/src/com/bottleworks/dailymoney/calculator2/.

Source file: Persist.java

  31 
vote

private void load(){
  try {
    InputStream is=new BufferedInputStream(mContext.openFileInput(FILE_NAME),8192);
    DataInputStream in=new DataInputStream(is);
    int version=in.readInt();
    if (version > LAST_VERSION) {
      throw new IOException("data version " + version + "; expected "+ LAST_VERSION);
    }
    history=new History(version,in);
    in.close();
  }
 catch (  FileNotFoundException e) {
    Calculator.log("" + e);
  }
catch (  IOException e) {
    Calculator.log("" + e);
  }
}
 

Example 47

From project datafu, under directory /src/java/datafu/linkanalysis/.

Source file: PageRank.java

  31 
vote

private Iterator<Integer> getEdgeData() throws IOException {
  if (!usingEdgeDiskCache) {
    return this.edges.iterator();
  }
 else {
    FileInputStream fileInputStream=new FileInputStream(this.edgesFile);
    BufferedInputStream inputStream=new BufferedInputStream(fileInputStream);
    final DataInputStream dataInputStream=new DataInputStream(inputStream);
    return new AbstractIterator<Integer>(){
      @Override protected Integer computeNext(){
        try {
          return dataInputStream.readInt();
        }
 catch (        IOException e) {
          return endOfData();
        }
      }
    }
;
  }
}
 

Example 48

From project dawn-isencia, under directory /com.isencia.passerelle.commons/src/main/java/com/isencia/util/.

Source file: FileLocator.java

  31 
vote

/** 
 * locateLocaleSpecificFileInClassPath returns a DataInputStream that can be used to read the requested file, but the name of the file is determined using information from the current locale and the supplied file name (which is treated as a "base" name, and is supplemented with country and language related suffixes, obtained from the current locale). The CLASSPATH is used to locate the file.
 * @param fileName The name of the file to locate. The file name may bequalified with a partial path name, using '/' as the separator character or using separator characters appropriate for the host file system, in which case each directory or zip file in the CLASSPATH will be used as a base for finding the fully-qualified file. Here is an example of how the supplied fileName is used as a base for locating a locale-specific file: <pre> Supplied fileName: a/b/c/x.y,  current locale: US English Look first for: a/b/c/x_en_US.y (if that fails) Look next for:  a/b/c/x_en.y (if that fails) Look last for:  a/b/c/x.y All elements of the class path are searched for each name, before the next possible name is tried. </pre>
 * @exception java.io.FileNotFoundException The requested class file could notbe found.
 * @exception java.io.IOException The requested class file could not beopened.
 */
public static DataInputStream locateLocaleSpecificFileInClassPath(String fileName) throws FileNotFoundException, IOException {
  String localeSuffix="_" + Locale.getDefault().toString();
  int lastSlash=fileName.lastIndexOf('/');
  int lastDot=fileName.lastIndexOf('.');
  String fnFront, fnEnd;
  DataInputStream result=null;
  boolean lastAttempt=false;
  if ((lastDot > 0) && (lastDot > lastSlash)) {
    fnFront=fileName.substring(0,lastDot);
    fnEnd=fileName.substring(lastDot);
  }
 else {
    fnFront=fileName;
    fnEnd="";
  }
  while (true) {
    if (lastAttempt)     result=locateFileInClassPath(fileName);
 else     try {
      result=locateFileInClassPath(fnFront + localeSuffix + fnEnd);
    }
 catch (    Exception e) {
    }
    if ((result != null) || lastAttempt)     break;
    int lastUnderbar=localeSuffix.lastIndexOf('_');
    if (lastUnderbar > 0)     localeSuffix=localeSuffix.substring(0,lastUnderbar);
 else     lastAttempt=true;
  }
  return result;
}
 

Example 49

From project DB-Builder, under directory /src/main/java/org/silverpeas/dbbuilder/.

Source file: DBBuilderPiece.java

  31 
vote

public DBBuilderPiece(String pieceName,String actionName,boolean traceMode) throws Exception {
  this.traceMode=traceMode;
  this.actionName=actionName;
  this.pieceName=pieceName;
  if (pieceName.endsWith(".jar")) {
    content="";
  }
 else {
    File myFile=new File(pieceName);
    if (!myFile.exists() || !myFile.isFile() || !myFile.canRead()) {
      DBBuilder.printMessageln(Console.NEW_LINE + "\t\t***Unable to load : " + pieceName);
      throw new Exception("Unable to find or load : " + pieceName);
    }
    int fileSize=(int)myFile.length();
    byte[] data=new byte[fileSize];
    DataInputStream in=new DataInputStream(new FileInputStream(pieceName));
    in.readFully(data);
    content=new String(data);
    in.close();
  }
  Properties res=DBBuilder.getdbBuilderResources();
  if (res != null) {
    for (Enumeration e=res.keys(); e.hasMoreElements(); ) {
      String key=(String)e.nextElement();
      String value=res.getProperty(key);
      content=StringUtil.sReplace("${" + key + "}",value,content);
    }
  }
}
 

Example 50

From project Diver, under directory /ca.uvic.chisel.javasketch/src/ca/gc/drdc/oasis/tracing/cjvmtracer/internal/.

Source file: OasisCommand.java

  31 
vote

/** 
 * Custom code for reading a command from an output stream.
 * @param in
 * @throws IOException
 * @throws ClassNotFoundException
 */
public static OasisCommand readExternal(InputStream inStream) throws IOException {
  DataInputStream in=new DataInputStream(inStream);
  int input=in.read();
  checkCommand(input);
  char command=(char)input;
  short s=in.readShort();
  int dataLength=(s & 0xFFFF);
  if (dataLength < 0 || dataLength > 0xFFFF) {
    throw new IOException("Data size out of range");
  }
  byte[] data=new byte[dataLength];
  if (dataLength > 0) {
    int read=in.read(data,0,dataLength);
    if (read != dataLength) {
      throw new IOException("Data length mismatch. Got " + read + " expected "+ dataLength);
    }
  }
  return new OasisCommand(command,data);
}
 

Example 51

From project DTRules, under directory /dsl/ebl/src/main/java/com/dtrules/compiler/ebl/.

Source file: EBL.java

  31 
vote

/** 
 * The actual routine to compile either an action or condition.  The code is all the same, only a flag is needed to decide to compile an action vs condition.
 * @param action    Flag
 * @param s         String to compile
 * @return          Postfix
 * @throws Exception    Throws an Exception on any error.
 */
private String compile(String s) throws RulesException {
  InputStream stream=new ByteArrayInputStream(s.getBytes());
  DataInputStream input=new DataInputStream(stream);
  DTRulesscanner lexer=new DTRulesscanner(input);
  tfilter=new TokenFilter(session,lexer,types,localtypes);
  DTRulesParser parser=new DTRulesParser(tfilter);
  Object result=null;
  parser.localCnt=localcnt;
  try {
    result=parser.parse().value;
  }
 catch (  Exception e) {
    int line=0;
    for (int i=0; i < lexer.linenumber(); i++) {
      int tryhere=s.indexOf("\n",line);
      if (tryhere > 0)       line=tryhere;
    }
    s=s.replaceAll("[\n]"," ");
    s=s.replaceAll("[\r]"," ");
    String before=s.substring(0,line + lexer.charnumber());
    String after=s.substring(line + lexer.charnumber());
    String location="Parsing a " + before.substring(0,before.indexOf(" "));
    before=before.substring(before.indexOf(" ") + 1);
    throw new RulesException("compileError",location,before + " *ERROR*=> " + after);
  }
  localcnt=parser.localCnt;
  localtypes.putAll(parser.localtypes);
  return result.toString();
}
 

Example 52

From project cascading, under directory /src/test/cascading/tuple/hadoop/.

Source file: TestTextComparator.java

  30 
vote

@Override public int compare(BufferedInputStream lhsStream,BufferedInputStream rhsStream){
  try {
    if (lhsStream == null && rhsStream == null)     return 0;
    if (lhsStream == null) {
      WritableUtils.readString(new DataInputStream(rhsStream));
      return -1;
    }
    if (rhsStream == null) {
      WritableUtils.readString(new DataInputStream(lhsStream));
      return 1;
    }
    String lhsString=WritableUtils.readString(new DataInputStream(lhsStream));
    String rhsString=WritableUtils.readString(new DataInputStream(rhsStream));
    if (lhsString == null && rhsString == null)     return 0;
    if (lhsString == null)     return -1;
    if (rhsString == null)     return 1;
    return lhsString.compareTo(rhsString);
  }
 catch (  IOException exception) {
    throw new CascadingException(exception);
  }
}
 

Example 53

From project Amoeba-for-Aladdin, under directory /src/java/com/meidusa/amoeba/mysql/parser/sql/.

Source file: MysqlParser.java

  29 
vote

/** 
 * main method to test parser
 */
public static void main(String args[]) throws com.meidusa.amoeba.parser.ParseException {
  MysqlParser p=null;
  if (args.length < 1) {
    System.out.println("Reading from stdin");
    p=new MysqlParser(System.in);
  }
 else {
    try {
      p=new MysqlParser(new DataInputStream(new FileInputStream(args[0])));
    }
 catch (    FileNotFoundException e) {
      System.out.println("File " + args[0] + " not found. Reading from stdin");
      p=new MysqlParser(System.in);
    }
  }
  if (args.length > 0) {
    System.out.println(args[0]);
  }
  Statment statment=p.doParse();
  System.out.println(statment.getExpression());
}
 

Example 54

From project android-client_1, under directory /src/com/googlecode/asmack/dns/record/.

Source file: SRV.java

  29 
vote

@Override public void parse(DataInputStream dis,byte[] data,int length) throws IOException {
  this.priority=dis.readUnsignedShort();
  this.weight=dis.readUnsignedShort();
  this.port=dis.readUnsignedShort();
  this.name=NameUtil.parse(dis,data);
}
 

Example 55

From project AsmackService, under directory /src/com/googlecode/asmack/dns/record/.

Source file: SRV.java

  29 
vote

@Override public void parse(DataInputStream dis,byte[] data,int length) throws IOException {
  this.priority=dis.readUnsignedShort();
  this.weight=dis.readUnsignedShort();
  this.port=dis.readUnsignedShort();
  this.name=NameUtil.parse(dis,data);
}
 

Example 56

From project devTrac, under directory /src/main/com/phonegap/io/.

Source file: ConnectionManager.java

  29 
vote

/** 
 * Loads an external URL and provides a connection that holds the array of bytes. Internal URLs (data://) simply pass through.
 * @param url a http:// or data:// URL 
 */
public InputConnection getPreLoadedConnection(String url){
  InputConnection connection=getUnmanagedConnection(url,null,null);
  if ((connection != null) && (!isInternal(url,null))) {
    try {
      final byte[] data=read(connection.openInputStream());
      close(connection);
      if (data != null) {
        connection=new InputConnection(){
          public DataInputStream openDataInputStream() throws IOException {
            return new DataInputStream(openInputStream());
          }
          public InputStream openInputStream() throws IOException {
            return new ByteArrayInputStream(data);
          }
          public void close() throws IOException {
            return;
          }
        }
;
      }
    }
 catch (    IOException ioe) {
      close(connection);
      System.out.println("Problems reading an external URL");
    }
  }
  return connection;
}