N.Y. Criminal Procedure Law § 170.25
3. At any time before entry of a plea of guilty to or commencement of a trial of or within thirty days of arraignment on an accusatory instrument specified in subdivision one, whichever occurs first, the defendant may apply to the local criminal court for an adjournment of the proceedings therein upon the ground that he intends to make a motion in a superior court, pursuant to subdivision one, for an order that the misdemeanor charge be prosecuted by indictment. In such case, the local criminal court must adjourn the proceedings to a date which affords the defendant reasonable opportunity to pursue such action, and may subsequently grant such further adjournments for that purpose as are reasonable under the circumstances. Following the granting of such adjournment or adjournments, the proceedings must be as follows:
4. Upon application of a defendant who on the basis of an order issued by a superior court pursuant to subdivision one is awaiting grand jury action, and who, at the time of such order or subsequent thereto, has been committed to the custody of the sheriff pending grand jury action, and who has been confined in such custody for a period of more than forty-five days without the occurrence of any grand jury action or disposition, the superior court which issued such order must release him on his own recognizance unless: